I’m trying to show a list of mssg
, but I get the following error:
Trying to access array offset on value of type bool
@foreach ($mssg as $mssg)
<tr>
<td>{{$mssg["objMessage"]}}</td>
<td>{{ $mssg["estDateMessage"] }} </td>
<td>
@if($mssg["active"]==0)
{{"message non lue"}}
@else
{{"messaage lue"}}
@endif
</td>
<td><button><a href="/mssg">lire</a></button></td>
<td><button>delete</button></td>
</tr>
@endforeach
This is my controller
function indexe() {
$x = Auth::User()->id;
$mess = Auth::User()->name;
$mssg = messages::find($x);
foreach($mssg as $m) {
dd($m["idUser"]);
}
return view('liate_message',["mssg"=>$mssg],["idd"=>$mess]);
}
2
Answers
Check your
foreach code
@foreach ($mssg as $mssg)
change to
@foreach ($mssg as $m)
then change all entries like
{{$mssg["objMessage"]}}
to{{$m["objMessage"]}}
You can change the
$m
to any variable names you want.Make sure variable
$mssg
=> not null and is_array.You should
dd
the$mssg
variable in the controller to check what it is, before returning$mssg
to the view.