这段代码适用于我程序的某些部分,但我想知道为什么我在这个问题上出现错误。这是我的代码
控制器
$mydate=Carbon::now()->addHours(8);
$newdate=$mydate->toDateString();
$myquery=DB::table('attendances')
->leftJoin('employees', 'attendances.user_id', '=', 'employees.id')
->where('date_only', '=', $newdate)
->orderBy('attendances.logon','asc')->get();
return View::make('home')->with($myquery);
视图
<table >
<tr>
<td>
First Name
</td>
<td >
Last Name
</td>
<td>
Time in
</td>
</tr>
@foreach ($myquery as $mytask)
<tr>
<td >
{{$mytask->firstname}}
</td>
<td >
{{$mytask->lastname}}
</td>
<td>
{{$mytask->logon}}
</td>
</tr>
@endforeach
</table>
我已经为此工作了几个小时,但我就是无法解决错误,我总是收到错误 500,请轻松帮助
以下是$myquery的var_dump
array(3) { [0]=>object(stdClass)#156 (11) { ["user_id"]=> int(21) ["登录"]=> 字符串(19) "2014-11-28 08:11:12" ["注销"]=> 字符串(19) "0000-00-00 00:00:00" ["date_only"]=>字符串(19) "2014-11-28 00:00:00" ["created_at"]=> 字符串(19) "2014-11-24 07:21:06" ["updated_at"]=> 字符串(19) "2014-11-24 07:21:06" ["in_out"]=> int(1) ["id"]=> int(21) ["名字"]=> 字符串(4) "杰克" ["姓氏"]=> 字符串(5) "巴尔巴" ["position"]=> string(6) "awdwad" } [1]=> object(stdClass)#157 (11) { ["user_id"]=> int(22) ["logon"]=> 字符串(19) "2014-11-28 08:11:17" ["注销"]=> 字符串(19) "0000-00-00 00:00:00" ["date_only"]=> 字符串(19) "2014-11-28 00:00:00" ["created_at"]=> 字符串(19) "2014-11-24 08:55:04" ["updated_at"]=>字符串(19) "2014-11-24 08:55:04" ["in_out"]=> int(1) ["id"]=> int(22) ["firstname"]=> 字符串(9) "Charmaine" ["姓氏"]=> 字符串(5) "Balba" ["位置"]=> string(10) "Programmer" } [2]=> object(stdClass)#158 (11) { ["user_id"]=> int(23) ["logon"]=> 字符串(19) "2014-11-28 08:11:27" ["注销"]=> 字符串(19) "0000-00-00 00:00:00" ["date_only"]=> 字符串(19) "2014-11-28 00:00:00" ["created_at"]=> 字符串(19) "2014-11-25 07:21:31" ["updated_at"]=> 字符串(19) "2014-11-25 07:21:31" ["in_out"]=> int(1) ["id"]=> int(23) ["firstname"]=> 字符串(3) "Kim" ["姓氏"]=> 字符串(7) "三星" ["位置"]=> string(10) "Programmer" } }
我还不能发表评论,但你的服务器日志说什么? 500 错误应在服务器错误日志中生成一行。
您没有将第二个参数传递给with
方法:
$tasks = DB::table('attendances')
->leftJoin('employees', 'attendances.user_id', '=', 'employees.id')
->where('date_only', '=', $newdate)
->orderBy('attendances.logon','asc')->get();
return View::make('home')->with('tasks', $tasks);
// then view:
@foreach ($tasks as $task)