【发布时间】:2021-07-07 16:30:35
【问题描述】:
我正在尝试在我的刀片模板中创建一个表。当我遍历数组一次时,我收到以下错误htmlspecialchars() expects parameter 1 to be string, array given 。
当我循环两次时,表格格式不正确。
我的刀片模板如下所示:
@foreach($checkins as $index=>$opt)
@foreach($checkins as $index=>$opt)
@foreach($opt as $key => $value)
<tr> {{$key}} </tr>
<td> {{$value}} </td>
@endforeach
@endforeach
我的控制器看起来像这样,我使用 getAddress 函数将纬度和经度转换为实际位置:
if($request->has('search')) {
$checkins = Checkin::with(['user'])->where('name', 'like', '%'.$request->search.'%')->paginate(setting('record_per_page', 15));
} else {
$checkins = Checkin::with(['user'])->get();
}
$title = "Manage Checkins";
$checkins = $checkins->map(function ($checkin) {
$location = $this->getAddress($checkin->lat,$checkin->long);
return [
'location' => $location,
'student' => $checkin->user->first_name. ' ' .$checkin->user->first_name,
'supervisor' => $checkin->supervisor === null ? '' : $checkin->supervisor->first_name. ' ' .$checkin->supervisor->last_name ,
'created_at' => $checkin->created_at,
];
});
return view('checkins.index', compact('checkins', 'title'));
如下所示的数组:
[
{
location: "Government of Southern Sudan Nairobi Liason Office, 5th Avenue Ngong, Hurlingham, Nairobi, P. O. BOX 41362, Kenya",
student: "Super Admin Super Admin",
supervisor: "Super Admin Admin",
created_at: null
},
{
location: "Kajiado, Kenya",
student: "Test Test",
supervisor: "Super Admin Admin",
created_at: "2021-07-06T12:13:54.000000Z"
},
{
location: "Murang`a, Central Kenya, Kenya",
student: "Test Test",
supervisor: "Super Admin Admin",
created_at: "2021-07-06T12:16:19.000000Z"
}
]
任何关于我如何将键显示为值和键下方的实际值的帮助/链接将不胜感激。
【问题讨论】: