Support the ongoing development of Laravel.io →
Eloquent Views

Coming over from Kohana to try out Laravel. I'm using the Homestead vagrant box. Following the Quickstart section, I set up a Route in the User model:

	Route::get('users', function()
{
	$users = User::all();
	return View::make('users')->with('users', $users);
});

And entered a simple foreach loop in users.blade.php:

@extends('layout')

@section('content')
@foreach ($users as $user)
    <p>{{ $user->name }}</p>
@endforeach

@stop

But loading http://homestead.app:8000/users in my browser returns an undefined variable error exception:

Undefined variable: users (View: /home/vagrant/Code/Laravel/app/views/users.blade.php) 

Now, true, my users table is still empty. But that shouldn't be causing an exception. What, if anything, in my code is preventing the $users variable from being passed to the view? What have I missed?

Last updated 2 years ago.
0

A little progress. The query isn't returning any data, even after I've entered a few rows. Must be a db connection problem.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

plweil plweil Joined 21 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.