I am new to laravel and I tried to fix the problem from here
I have a controller as shown below:
foreach($users as $user){
$message[] = Model::where('id',$user->id)->get();
}
$data['tests'] = $message;
return View::make('user.index', $data);
My view:
@foreach($tests['message'] as $test)
id : {{$test->id}}
@endforeach
what gives me Undefined index: message
I dumped $datain the controller. my array is shown below. I put var_dump in the controller before the return statement. my var_dump($data)shows:
array(1) {
["tests"] => array(2) {
[0] => object(Illuminate\ Database\ Eloquent\ Collection)
[0] => ["attributes": protected] => array(14) {
["id"] => string(3) "12"....
}
}
[1] => object(Illuminate\ Database\ Eloquent\ Collection)
[0] => ["attributes": protected] => array(14) {
["id"] => string(3) "12"....
}
}
}
what am I doing wrong. Please help me
source
share