我在Laravel 5.2中遇到一个Eloquent模型问题。我的模型是User
,Authenticatable
的子类,每当我将名为last_activity
的日期字段设置为Carbon::now()
时,它也会将created_at
设置为当前时间。
我正在使用此查询修改条目:
$user->last_activity = Carbon::now();
$user->save();
这是我的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'];
}
请确保您使用的是日期时间,而不是时间戳作为mysql 中的字段类型