This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
VadimIzmalkov
In my plugin I have two models:
- Manager
- Office
In office model I have relation:
public $hasMany = [
'managers' => [Manager::class, 'key' => 'office_id'],
];
Each manager belong to some office and related to backend user:
public $belongsTo = [
'backend_user' => [BackendUser::class],
'office' => [Office::class]
];
In Office form I have relation widget and want to use full name as nameFrom value:
fields:
managers:
type: relation
label: Managers
nameFrom: full_name
But full name (fisrt name and last name) is stored in backend user:
$first_name = $manager->backend_user->first_name;
$last_name = $manager->backend_user->last_name;
The idea was to create a mutator in manager model:
public function getFullNameAttribute()
{
return $this->backend_user->first_name.' '.$this->backend_user->last_name;
}
But in this case name gets from first model, not from each, and I got all checkboxes with same name.
How can I achive that?
1-1 of 1