I am trying to create a table in my blade template. When i loop through the array once, i get the following error htmlspecialchars() expects parameter 1 to be string, array given .
When i loop twice, i get an incorrect table format.
My blade template looks like this :
@foreach($checkins as $index=>$opt)
@foreach($checkins as $index=>$opt)
@foreach($opt as $key => $value)
<tr> {{$key}} </tr>
<td> {{$value}} </td>
@endforeach
@endforeach
My controller looks like this, i converted the latitude and longitude to an actual location using the getAddress function :
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'));
The array that looks like this :
[
{
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"
}
]
Any assistance/links on how i can display the keys as the values and the actual values below the keys will be appreciated.
