access Team model attribute like name by the roles() relationship #2172
-
Hello, I have a project with Laravel Permission Package. But i don't know how I can access to my Team attributes like the name. Should I create un belongsTo relation beetween roles() relation and Team Model? In other words : if I have a team_id = 6 in my 'model_has_roles' table, how can I access to the Team name with id = 6. thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
If you need that, Yes,
Also, you could try with |
Beta Was this translation helpful? Give feedback.
-
Sorry for markdown... for information I do This : $relation = $this->morphToMany(
config('permission.models.role'),
'model',
config('permission.table_names.model_has_roles'),
config('permission.column_names.model_morph_key'),
PermissionRegistrar::$pivotRole
);
$relation
->join('structures', 'structures.id', '=', 'model_has_roles.structure_id')
->addSelect(\DB::raw('structures.name as structure_name')); And Secondly, how can I retrieve the others structure table fields ? |
Beta Was this translation helpful? Give feedback.
If you need that, Yes,
I have a belongsTo relation between the User and Team model, and I only needed that
Also, you could try with
join
on that relation