I'm doing my project using Laravel framework. Everything seems to be perfect. However, in my login part, I want to do something like when a user login into the system, it will check the "is_admin" column. If the "is_admin" column is equal to 1, it will go straight to admin page. I've been looking on the Internet but I can't find the answer for this. I also did use Middleware but it didn't work. I don't know why. Can somebody help me with this one. Thanks
Asked
Active
Viewed 385 times
2 Answers
0
Laravel 5.1 allows authorization, you can add something like this in your AuthServiceProvider
public function boot(GateContract $gate){
$gate->define('admin', function($user){
return $user->is_admin;
});
}
Then use the Gate
facade in your controllers like
$user=Auth::user();
if(Gate::allows('admin', $user)){
//user is admin
}
Take a look at this part of Laravel's documentation http://laravel.com/docs/5.1/authorization

Saad
- 1,155
- 3
- 16
- 36
0
You can write this in your AuthController.php
if(Auth::user()->is_admin == 1){
protected $redirectTo = 'admin';
}else{
protected $redirectTo = 'member';
}
The avobe code is only for redirection. You can use middleware to protect admin panel from member.

smartrahat
- 5,381
- 6
- 47
- 68