Support the ongoing development of Laravel.io →
Authentication Authorization
Last updated 2 years ago.
0

Hey!

You're doing a mix of a few things here:

  1. You are assigning only one role_id to a user directly in the users table.
  2. You are using belongsToMany relationships even though your user only has one single role.

So you have to choose, do you want to assign multiple roles to a user, then belongsToMany would be correct and role_id should be removed from the users table. OR Do you want to assign only one role to a user, then all the other code needs to be updated and the belongsToMany needs to be converted to a belongsTo relationship.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Razvan ajax30 Joined 2 Oct 2021

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.