Reputation: 5859
I created a table of users and I added a field called role and this line of code will not work when I use it in a filter, the problem is in the Auth::user()->role part
Route::filter('products.admin', function()
{
if (Auth::user()->role !== 'admin')
return Redirect::to('/');
});
Does any one know how to get the role field to be recognized for the user
Upvotes: 0
Views: 104
Reputation: 419
You need to have something like this in your routes:
Route::get('products', array('before' => 'auth|products.admin', 'uses' => 'ProductsController@index'));
This way, you first check the user is authenticated and then you check that it has the correct role.
Upvotes: 0
Reputation: 111829
If you really have a role
field in your table, you should probably use:
Route::filter('products.admin', function()
{
if (!Auth::check() || Auth::user()->role != 'admin')
return Redirect::to('/');
});
Upvotes: 1