Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

murilo's avatar
Level 10

User and Roles Gate

Hello Guys , I use to make a muth authentication like this -

https://laracasts.com/lessons/users-and-roles

but now in Laravel 5.6 , is not working this type of Authentication , maybe somethis has changed .

In AuthServiceProvider , I have this code -

use Illuminate\Support\Facades\Gate as GateContract;

  public function boot(GateContract $gate)
    {
        $this->registerPolicies();


        foreach ($this->getPermissions() as $permission){

            $gate->define($permission->title , function($user) use ($permission){
                return $user->hasRole($permission->roles);
            });

        }


    }

    protected function getPermissions(){
        return UserPermission::with('roles')->get();
    }

but is giving this error

Class 'App\Providers\Gate' not found

dows some one knows what is happenig ?

0 likes
4 replies
Vilfago's avatar

On which line do you have the error ?

petrit's avatar

Add this line on the top

use Illuminate\Support\Facades\Gate;
...
Vilfago's avatar

Did you define a namespace before this line ?

murilo's avatar
Level 10

I have found the mistake , I have to do like this -

$gate->define

Thanks

Please or to participate in this conversation.