You don't signin the admin
$this->actingAs($adminUser)->get('admin-dashboard);
Do you seed the roles and permissions separately somewhere in the test suite?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to extend the Spatie\Permission\Models\Role class. I created a new Role class in App\Models\Role like below
use Spatie\Permission\Models\Role as SpatieRole;
class Role extends SpatieRole
{
use HasFactory;
}
Everything works and I can create roles and assign them to users. Fine, but as soon as I update the app\config\permission.php to use my model it breaks all tests, but the application works fine. Below is my permission.php
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your roles. Of course, it
* is often just the "Role" model but you may use whatever you like.
*
* The model you want to use as a Role model needs to implement the
* `Spatie\Permission\Contracts\Role` contract.
*/
'role' => App\Models\Role::class,
In my test I am simply creating a user, assigning them a role which has permission to view a route.
// My Test
$adminUser = User::factory()->create(); // Create user
$adminUser->assignRole('Admin'); // assign admin role
$this->actingAs($adminUser); // Login as admin
$this->get('admin-dashboard'); // visit admin route
// My route
Route::get('admin/dashboard', AdminDashboardController::class)->name('admin-dashboard')->middleware(['can:Administer Site']);
Like i said this work fine when the models.role attribute in the permission.php config file uses the spatie Role class, but once I switch it to my role which extends the Spatie role i get a 403 forbidden in my tests. What's even weirder is this works in the browser just fine. I can visit the route.
You don't signin the admin
$this->actingAs($adminUser)->get('admin-dashboard);
Do you seed the roles and permissions separately somewhere in the test suite?
Please or to participate in this conversation.