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

kylemabaso's avatar

User does not have the right permissions

Hi.

I've setup roles and permissions using the Spatie package. I get a 403 error when I try to access the roles route but I can access all the other routes. Below is my routes code:

Route::middleware('auth')->group(function() {
    Route::get('/', [PageController::class, 'dashboard'])->name('dashboard');
    Route::get('logout', [AuthController::class, 'logout'])->name('logout');
    Route::resource('roles', RoleController::class);
    Route::resource('users', UserController::class);

RoleController

class RoleController extends Controller
{

    function __construct()
    {
        $this->middleware('permission:role-list|role-create|role-edit|role-delete', ['only' => ['index','store']]);
        $this->middleware('permission:role-create', ['only' => ['create','store']]);
        $this->middleware('permission:role-edit', ['only' => ['edit','update']]);
        $this->middleware('permission:role-delete', ['only' => ['destroy']]);
    }

    public function index(Request $request)
    {
        $roles = Role::orderBy('id','DESC')->paginate(5);
        return view('roles.index',compact('roles'));
    }
0 likes
3 replies
Snapey's avatar

user doesn't have the right permissions !

kylemabaso's avatar

@Snapey I figured it out, I created the user and role on the DB before I created the permissions. It works now.

akzeitlos's avatar

Hello, same Problem here. I set an admin user and set all permissions and connected the permission with the role, but no success. What to do?

Please or to participate in this conversation.