Using accessor in RelationManager AttachAction not working

I have following database structure: User - email - person_id Person - firstname - lastname and I have created an accessor in my User model:
protected $with = ['person'];

public function person()
{
return $this->belongsTo(Person::class);
}

public function name(): Attribute
{
return Attribute::make(
get: fn () => "{$this->person->firstname} {$this->person->lastname}",
);
}
protected $with = ['person'];

public function person()
{
return $this->belongsTo(Person::class);
}

public function name(): Attribute
{
return Attribute::make(
get: fn () => "{$this->person->firstname} {$this->person->lastname}",
);
}
My RelationManager:
class UserRelationManager extends RelationManager
{
protected static string $relationship = 'users';

public static function getRecordTitleAttribute(): ?string
{
return 'name';
}

....

->headerActions([
AttachAction::make(),
])
class UserRelationManager extends RelationManager
{
protected static string $relationship = 'users';

public static function getRecordTitleAttribute(): ?string
{
return 'name';
}

....

->headerActions([
AttachAction::make(),
])
and I expect that this accessor will be used in the RelationshipManager, but it is not. When trying to add a User to a Role I have this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.name' in 'where clause' (Connection: mysql, SQL: select distinct `users`.* from `users` left join `model_has_roles` on `users`.`id` = `model_has_roles`.`model_id` where (`users`.`name` like %myName%) and not exists (select * from `roles` inner join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id` where `users`.`id` = `model_has_roles`.`model_id` and `model_has_roles`.`model_type` = App\Models\User and `roles`.`id` = 1) order by `users`.`name` asc limit 50)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.name' in 'where clause' (Connection: mysql, SQL: select distinct `users`.* from `users` left join `model_has_roles` on `users`.`id` = `model_has_roles`.`model_id` where (`users`.`name` like %myName%) and not exists (select * from `roles` inner join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id` where `users`.`id` = `model_has_roles`.`model_id` and `model_has_roles`.`model_type` = App\Models\User and `roles`.`id` = 1) order by `users`.`name` asc limit 50)
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?