Lovelock
Lovelock

Reputation: 8075

Custom Laravel Route Filter Not Working

Trying to work on a custom filter to determine a users rights.

In my DB users table I have a field called rights. All admins have a rights value of 5.

I created a filter:

Route::filter('admin', function()
{ 
if (Auth::check()) {
  if (Auth::user()->rights !== 5)
  {
    return Redirect::to('/'); 
  }
}
else
{
    return Redirect::to('login');
}
}); 

Which SHOULD check if the user is logged in and then check their rights. If the rights are not 5, they get sent back to the root, or if they are not logged in they get asked to login.

I am using the role like this:

Route::get('admin', array('before' => 'admin', function()
{
  return View::make('admin/index', array('pageTitle' => 'Admin'));
}));

At the moment this always sends the user to login / the root, even if their rights are set as 5. Any help?

Upvotes: 1

Views: 288

Answers (1)

Rafael
Rafael

Reputation: 7746

!== means identical (type and value)

Auth::user()->rights is a string from the db.

Instead use !=

Upvotes: 1

Related Questions