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

basilpjoy's avatar

Roles and Permissions with admins table

I am using table "admins" instead of "users" and using roles and permissions. Also I used the all codes same like in the tutorial, but I am not getting the proper result This is the code am using in AuthServiceProvider.php

    public function boot(GateContract $gate)
    {
        $this->registerPolicies($gate);
       
       foreach ($this->getPermissions() as $permission) {
           $gate->define($permission->name, function($admin) use ($permission){
                return $admin->hasRole($permission->roles);
           });
       }
    }

    public function getPermissions(){
        return Permission::with('roles')->get();
    }

I am new to Laravel please provide a solution I followed this tutorial "https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/16"

0 likes
4 replies
jlrdw's avatar

Please search first as there has been quite a few post on Authentication admins roles etc.

basilpjoy's avatar

Thanks for the advise jlrdw,

I already searched many time and in all posts they are telling about admin permission in 'users' table. If am using users table this same code is working for me perfectly, but I have a different table with name 'admins' for this I have to assign roles. I hope you understand my requirement.

basilpjoy's avatar

I already configured my auth.php

return [
'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],

        'admin' => [
            'driver' => 'session',
            'provider' => 'admin',
        ],
    ],
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        'admin' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],        
    ],
'passwords' => [
        'users' => [
            'provider' => 'users',
            'email' => 'auth.emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        
        'admins' => [
            'provider' => 'admin',
            'email' => 'auth.emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

like this Login and everything working fine, only have problem with permission. Please don't get angry am doing my first project in Laravel

Please or to participate in this conversation.