Reputation: 3506
I want to make a route filter in Laravel 4 for my application.
Details:
I know for sure that {{ Auth::user()->distributor()->first()->type }}
will return OEM
Here is the code in my filters.php
Route::filter('distributor', function()
{
if (Auth::user()->distributor()->first()->type !== "OEM" )
{
if (Request::ajax())
{
return Response::make('Unauthorized', 404);
}
}
else return View::make('errors.404_auth');
});
I got an error :
Upvotes: 0
Views: 24
Reputation:
I saw you tried to access the relation between the user and the distributor, but you have not check to the if the user with that particular type is actually exist.
My suggestion will be
Add if (Auth::user()->type == " You user type in string "){
on top of your first if statement.
See the code for detail. I hope this help !
Route::filter('oem', function()
{
if (Auth::user()->type == " You user type in string "){
if (Auth::user()->distributor()->first()->type == "OEM")
{
if (Request::ajax())
{
return Response::make('Unauthorized', 404);
}
}
else return View::make('errors.404_auth');
}
});
Upvotes: 1