Here is a solution to this: https://stackoverflow.com/a/45313980/1457270
so you need to add the guard you are using on each check, or override the method in a base controller as it is shown in the SO answer.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone,
I’ve recently changed the authentication system in my Laravel application to use the Admin model instead of the default User model. Everything related to authentication is working fine, but I’m facing an issue with Gate.
Here’s what I’ve done:
In my AppServiceProvider, I defined a simple gate like this:
use Illuminate\Support\Facades\Gate;
public function boot(): void
{
Gate::define('amir', function () {
dd('Gate is being evaluated'); // For debugging
return true;
});
}
I tried testing the gate using Gate::allows() in a route:
Route::get('/test-gate', function () {
if (Gate::allows('amir')) {
return 'Gate passed!';
}
return 'Gate denied!';
});
However, the gate never seems to be triggered, and the dd('Gate is being evaluated') inside the closure is not executed.
I suspect it might have something to do with switching the authentication to the Admin model. For context, here’s what I’ve done to switch the authentication model:
Updated config/auth.php to use the Admin model for the web guard:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| If you have multiple user tables or models you may configure multiple
| providers to represent the model / table. These providers may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],
'admins' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\Admin::class), // This handles the admins table
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
and this is my Admin.php model
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable
{
use HasFactory;
protected $fillable = [
'email',
'password',
];
}
How can I fix the gate so that it works with the Admin model?
Please or to participate in this conversation.