1

I'm experiencing a problem in Laravel 5.2 with an Eloquent Model. My model is a User, subclass of Authenticatable and whenever I set a date field called last_activity to Carbon::now(), it also sets created_at to the current time.

I am modifying the entry with this query:

$user->last_activity = Carbon::now();
$user->save();

This is my app\User.php:

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Auth\Passwords\CanResetPassword;

class User extends Authenticatable
{
    use SoftDeletes, CanResetPassword;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'handle', 'email', 'password', 'confirmation_code'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'last_ip', 'updated_at', 'email', 'confirmed', 'confirmation_code', 'updated_at', 'deleted_at'
    ];

    protected $dates = ['last_logged_in', 'last_activity', 'created_at', 'updated_at', 'deleted_at'];
}
4

1 回答 1

0

Be sure you are using datetime and no timestamp as a field type in mysql

于 2015-12-31T06:49:22.483 回答