Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

First off your relations with pivot tables (many-to-many) must be set as belongsToMany not hasMany (which is 1-many). Next, the easiest way to define all those relations will be by following laravel rules, which are:

pivot table is named after model in alphabetical order: permission_user, permission_role, permission_position, position_user, role_user

At last to get the permissions you need for a given user, you need to load all permission (through role, position or whatever) and then merge them, to get the result. You can't do it in a single relation like you did in the last piece of code.

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

IAmMamba iammamba Joined 14 Apr 2014


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.