Replies: 2 comments 1 reply
-
If you agree with this idea I'm ready/hot to propose a pull request 😉 But ... I've no idea on which UnitTest to make ... |
Beta Was this translation helpful? Give feedback.
-
@Cyrille37 Interestingly enough, I've been working on code to do very similar but not specifically in relation to teams. This is the angle I've been working on, including the naming convention of the config key as it will probably become when finished: public function roles(): BelongsToMany
{
$relation = $this->morphToMany(
config('permission.models.role'),
'model',
config('permission.table_names.model_has_roles'),
config('permission.column_names.model_morph_key'),
app(PermissionRegistrar::class)->pivotRole
config('permission.table_names.model_has_roles'),
config('permission.column_names.model_morph_key'),
app(PermissionRegistrar::class)->pivotRole
- );
+ )->using(config('permission.models.pivot_model_has_roles'));
... (When I think then you could add your team-specific pieces to that Pivot model, without having to add the Also be aware that using the additional pivot model (instead of leaving it null) adds 1 more query to Eloquent's query chain. Tests for something like this are indeed the bottleneck. Functionally it works. Simulating it for testing is where I'm hitting a wall. |
Beta Was this translation helpful? Give feedback.
-
Hi,
To automatically fill some pivot data, like
team_id
, with an Observer or Event, it miss theMorphPivot
to theHasRoles::roles()
relation.To make it possible I add a
config('permission.models.role_pivot')
like
'role_pivot' => \App\Models\Permission\ModelHasRole::class
Then override the
HasRoles::roles()
in case ofteams
is active :Then I can have an Observer or Event that automatically fill some role data :
Beta Was this translation helpful? Give feedback.
All reactions