I have the following code in my routes.php file:
Route::get('org', function()
{
$org = Org::all();
return View::make('org.index')
->with('org', $org)
->with('category', 'Org');
});
When I visit /org in my application I receive the following error:
ErrorException
Undefined variable: category (View: /var/www/html/.../app/views/org/index.blade.php)
I have the following code in my index.blade.php file:
@if($category == 'Org')
@foreach($org as $organization)
...
@endforeach
@endif
If I remove the if statement (which references the $category variable) everything works just fine.
Why is $category not defined in the view?
EDIT:
This is rather embarrassing, but I'm going to describe the problem in case someone else finds it useful.
I have a lot of comments and duplicate code in my routes.php file as this is my first time using Laravel and I'm testing things out. It turns out I had a duplicate of the above route (though closer to the bottom of the routes.php file) which did not pass the $category variable to the view. I removed it and this solved my problem.
I was under the impression that if there were duplicate routes, the one described first would be used.