我有模特:
$tour = new Tour();
将数据添加到对象$tour
后:
$tour->date_start_at = $request->date_start_at;
$tour->date_end_at = $request->date_end_at;
$tour->save();
数据库中的字段date_start_at
和tour->date_end_at
是datetime
类型。
同样在我的模特中我有:
protected $dates = ['created_at', 'updated_at','date_start_at', 'date_end_at'];
当我尝试保存它时,我得到:
InvalidArgumentException in Carbon.php line 425:
Unexpected data found.
Unexpected data found.
Data missing
答案 0 :(得分:1)
使用Carbon解析数据:
$tour->date_start_at = Carbon::parse($request->date_start_at);
$tour->date_end_at = Carbon::parse($request->date_end_at);
$tour->save();