我的Information模型中有以下赋值方法:(用户有information方法)
public function setMyDateAttribute($value){
$this->attributes['my_date'] = \Carbon\Carbon::createFromFormat('d-m-Y', $value);
}和
$user->information()->update($request->get('information'));但是什么都没发生。
但如果我这么做了:
$information = $request->get('information');
$information['my_date'] = \Carbon\Carbon::createFromFormat('d-m-Y', $information['my_date']);
$user->information()->update($information);它工作得很完美
我错过了什么?
谢谢
发布于 2016-07-23 13:54:48
你的问题有点令人困惑,但从你的问题中给出的例子,我猜你希望Laravel像( my_date -at/updated_at)时间戳一样处理你的更新字段。如果是这样,那么您应该在模型的$dates字段中添加my_date名称,例如:
protected $dates = ['created_at', 'updated_at', 'my_date'];如果您使用的是softDeleting,则还要将deleted_at添加到该$dates阵列中。Read more here。
https://stackoverflow.com/questions/38538504
复制相似问题