murilo
175
1
Laravel

ACL in Laravel , auth

Posted 8 months ago by murilo

Hello , I am trying to make a ACL auth in Laravel like this tutorial - https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/13

It is working , I have all my users in the same table ( USERS table ) and its use the same guard , they are divided by roles , like this -

ADMIN - $user->hasRole('admin') CLIENTS - $user->hasRole('client') ....

In the login auth / verification , I have to make like this ->

//  search the user 
  $user =  User::where('email' , $request['email'] )->first();

// if has user and the user is admin 
if(! $user || ! $user->hasRole('admin')  ) {

// start making credentials
 $credentials = ['email' => $request['email'], 'password' => $request['password']];

    // verify again
        if(auth()->guard()->attempt($credentials)){

          return true;

        }


Does have any better way to do that ? something like this ->



// start making credentials
 $credentials = ['email' => $request['email'], 'password' => $request['password']];

    // verify again
        if(auth('admin')->guard()->attempt($credentials)){

          return true;

        }

Please sign in or create an account to participate in this conversation.