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

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.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

IAmMamba iammamba Joined 14 Apr 2014

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.