DateTime::__construct(): Failed to parse time string (from)



我得到这个错误

DateTime::__construct(): Failed to parse time string (from) at position 0 (f):在数据库中找不到时区

我尝试了不同的方法来解决这个错误。但根本没有成功。

$from = null;
$to = null;
try{
if ($request->input('from') || $request->input('to')) {
if ($request->input('from')) {
$from = Carbon::createFromFormat('Y-m-d', $request->input('from'))->toDateString();
}
if ($request->input('to')) {
$to = Carbon::createFromFormat('Y-m-d', $request->input('to'))->toDateString();
}
$validator = Validator::make(
[
'from' => $from,
'to'   => $to
],
[
'from' => 'required|date|date_format:Y-m-d',
'to'   => 'required|date|date_format:Y-m-d|after_or_equal:from',
]
);
if ($validator->fails()) {
return Redirect::back()
->with(array('flash_message' => "Please Enter Correct Date Format"));
}
}
} catch (Exception $e)
{
Log::debug("Time invalid ");
}

问题是火在这里,我认为$validator->fails()

有人知道这个吗?

// Validate that the strings have a date format
$validator = Validator::make(
$request->all(),
[
'from' => 'required|date|date_format:Y-m-d',
'to'   => 'required|date|date_format:Y-m-d|after_or_equal:from',
]
);
if ($validator->fails()) {
return Redirect::back()
->with(array('flash_message' => "Please Enter Correct Date Format"));
}
// Then after validation, use the string to create date objects
$from = Carbon::createFromFormat('Y-m-d', $request->input('from'));
$to = Carbon::createFromFormat('Y-m-d', $request->input('to'));

相关内容

  • 没有找到相关文章

最新更新