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


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.


Sign in to participate in this thread!


Your banner here too?

Razvan ajax30 Joined 2 Oct 2021


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

Your logo here?

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

© 2024 - All rights reserved.