Support the ongoing development of Laravel.io →
posted 9 years ago
Authentication
Last updated 2 years ago.
0

one way could be to use the construct()method in the Controllers used for admin tasks like so:

public function __construct()
{
    parent::__construct();
    $this->beforeFilter('admin');
}

and then you filter it eg

Route::filter('admin', function()
{
	if (Auth::user()->admin != 1) return Redirect::to('/');
});

which, in this case, assumes you have an admin field set up in your users table with a boolean 1 or 0

0
Solution

ooops, just saw you're working on L5. Then you should use middleware: http://mattstauffer.co/blog/laravel-5.0-middleware-filter-style

0

Thank u, watched about middleware yesterday evening.

Fine for me.

0

If you need a little bit more control you can try Laraguard. It's a permission module I wrote to protect controllers and/or methods and quite easy to use.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

gelnor gelnor Joined 20 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.