<?php
class OrganisationUser extends Pivot
{
use HasRoles;
// Config files do this for the User model. We do it by setting it manually here.
protected $guard_name = 'web';
// The table needs an id so that it can be referenced by the model_has_roles table.
public $incrementing = true;
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->with('roles');
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class)->with('roles');
}
public function organisationRoles(): BelongsToMany {
return $this->roles();
}
protected function rolesNames(): Attribute
{
return Attribute::make(
get: fn () => $this->roles->pluck('name'),
);
}
}
<?php
class OrganisationUser extends Pivot
{
use HasRoles;
// Config files do this for the User model. We do it by setting it manually here.
protected $guard_name = 'web';
// The table needs an id so that it can be referenced by the model_has_roles table.
public $incrementing = true;
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->with('roles');
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class)->with('roles');
}
public function organisationRoles(): BelongsToMany {
return $this->roles();
}
protected function rolesNames(): Attribute
{
return Attribute::make(
get: fn () => $this->roles->pluck('name'),
);
}
}