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

supptech's avatar

Routes check Permissions/Roles

Hey guys, in my web.php i got this route with permissions check:

Route::group(['middleware' => ['permission:test']], function () {
Route::middleware(['auth:sanctum', 'verified'])->get('/rent/processes', 
[\App\Http\Controllers\RentController::class, 'renderProcesses'])->name('renderProcesses');
});

in my database i added for my user the role with the permission test, and i added the permission direkt to my User.

INSERT INTO `permissions` (`id`, `name`, `desc`, `guard_name`, `created_at`, `updated_at`)
VALUES (8, 'test', '', 'web', NULL, NULL);

INSERT INTO `roles` (`id`, `name`, `guard_name`, `created_at`, `updated_at`, `desc`)
VALUES (2, 'TestRole', 'web', '2021-12-06 11:15:03', '2021-12-06 11:15:03', '');

INSERT INTO `model_has_permissions` (`permission_id`, `model_type`, `model_id`) VALUES (8, 
'App\Models\User', 1);

INSERT INTO `model_has_roles` (`role_id`, `model_type`, `model_id`) VALUES
(2, 'App\Models\User', 1);

INSERT INTO `role_has_permissions` (`permission_id`, `role_id`)VALUES (8, 2);

But the function $authGuard->user()->can($permission) always return false. but i dont know why, can u. help me?

When i check the Role, f.e.

Route::group(['middleware' => ['role:TestRole']], function () { ...

this works for me.

0 likes
1 reply
supptech's avatar
supptech
OP
Best Answer
Level 1

Hey,

php artisan permission:cache-reset 

fix my problem ...

Please or to participate in this conversation.