我通过ajax从我的表单中发布一个日期,格式如下:
27/07/2016
当它到达我的控制器时,我将其格式转换为Y-m-d,因为它在我的数据库中存储的格式是这样的。
然而,我收到以下错误:
DateTime::__construct(): Failed to parse time string (27/07/2016) at position 0 (2): Unexpected character
我的控制器
public function call(Request $request)
{
return Company->expenses()->where('date_expense', Carbon::parse($request->start)->format('Y-m-d'))->get();
}
在我的费用模型中,我将以下内容定义为日期:
protected $dates = ['date_expense'];
Carbon :: createFromFormat
而不是Carbon :: parse
。 - ceejayoz