类型错误:DateTime::__construct() 期望参数 1 是字符串,laravel 中给出的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48101180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type error: DateTime::__construct() expects parameter 1 to be string, object given in laravel
提问by Rashed Hasan
I am trying to get late time. $latetime1 returning correct but $latetime2 not returning same as $latetime1. $systemIntime value format and $inTime value format are the same. But I am getting above error for $latetime2. What should be the correct one, please someone help me. Here is my function bellow -
我正在努力争取迟到。$latetime1 返回正确但 $latetime2 不返回与 $latetime1 相同。$systemIntime 值格式和 $inTime 值格式相同。但是我遇到了 $latetime2 以上的错误。什么应该是正确的,请有人帮助我。这是我的功能波纹管 -
public function update(Request $request, Attendance $attendance)
{
$attendance = Attendance::find($attendance->id);
$inTime = $attendance->intime;
// late time caculate
$systemIntime = DB::table('schools')
->join('users', 'schools.id', '=', 'users.school_id')
->select('schools.intime')
->first();
$latetime1 = (new \DateTime($inTime))->format('H:i:s');
$latetime2 = (new \DateTime($systemIntime))->format('H:i:s');
$late = $latetime1->diff($latetime2);
回答by Alexey Mezenin
You're passing the whole object instead of its property, so change this:
你传递的是整个对象而不是它的属性,所以改变这个:
DateTime($systemIntime)
To:
到:
DateTime($systemIntime->intime)