I have some user data I need to share with all views, a list of 'types' owned by the user. I have setup a view::share to accomplish this, and placed it inside my routes.php inside an 'auth' filtered group like so:
routes.php
/* Authenticated group */
Route::group( array('before' => 'auth'), function() {
// Bring list of user's Types into views for sidebar menu generation
View::share( 'types', User::find( Auth::user()->id )->types );
/* Some user routes */
});
This works properly when the user is logged in, however when they are logged out it throws Trying to get property of non-object
error. Am I misunderstanding how route filtering works? I'm guessing this View::share
is still being processed even though it is inside the 'auth' filtered route group.
What is the proper way to do this? Should I create a Route::filter
to share the data and then apply it to the route group?