Hello, i want to pass an array of all users that have in the field: number='1'
My controller:
public function getUsers(){
$users = User::where('number','=',1);
return View::make('account.info')->with('users', $users);
}
My view info:
@foreach ($users as $user)
<p>This is user {{ $user->id }}</p>
@endforeach
It does not work. Somone can help me?
You forgot to fetch the rows from your query. To do that don't forget to use get() at the end of the query.
Fetch the rows like this:
$users = User::where('number', '=', 1)->get();
Thanks is perfect. Now i want to make something like a if else but with foreach. Is it posible?
@if ($users)
@foreach ($users as $user)
<p>This is user {{ $user->id }}</p>
@endforeach
@else
No users
@endif
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community