lundi 14 décembre 2020

Undefined index Visitor

i want to calculate visit to mywebsite so this is code i have on my model :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Visitor extends Model
{


protected $fillable = [ 'ip', 'visitdate','visittime' ];
protected $table = 'table_visitor';

public static function boot() {
    // Any time the instance is updated (but not created)
    static::saving( function ($tracker) {
        $tracker->visit_time = date('H:i:s');
        $tracker->hits++;
    } );
}

public static function hit() {
    static::firstOrCreate([
              'ip'   => $_SERVER['REMOTE_ADDR'],
              'visitdate' => date('Y-m-d'),
          ])->save();
}
}

when i want call this model to controller, its not detected, but when i am delete this part

public static function boot() {
    static::saving( function ($tracker) {
        $tracker->visit_time = date('H:i:s');
        $tracker->hits++;
    } );
}

public static function hit() {
    static::firstOrCreate([
              'ip'   => $_SERVER['REMOTE_ADDR'],
              'visitdate' => date('Y-m-d'),
          ])->save();
}

its work, so how to fix it ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37hxNOY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire