I have 3 tables using the same pivot table. I am trying to be able to edit the value in Nova, but it seems to be completely ignoring the field.
An Employee can work for multiple Companies, and will have a Title and Role specific to that company. So the title and role are kept as pivot data.
-- employees
- id
- name
-- companies
- id
- name
-- roles
- id
- name
-- company_employee
- id
- company_id
- employee_id
- title
- role_id
employee belongsToMany company
employee belongsToMany role
company belongsToMany role
role belongsToMany company
role belongsToMany employee
class Employee
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class, 'company_employee')
->withPivot(['id', 'title', 'role_id']);
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'company_employee', 'employee_id', 'role_id', 'id', 'id')
->withPivot(['id', 'title', 'role_id']);
}
Class Company
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'company_employee', 'company_id', 'role_id', 'id', 'id')
->withPivot(['id', 'title', 'role_id']);
}
Class Role
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class, 'company_employee', 'role_id', 'company_id', 'id', 'id')
->withPivot(['id', 'title', 'role_id']));
}
public function employees(): BelongsToMany
{
return $this->belongsToMany(Employee::class, 'company_employee', 'role_id', 'employee_id', 'id', 'id')
->withPivot(['id', 'title', 'role_id']));
}
In Nova for the employee resource I have:
BelongsToMany::make('Companies', 'companies')
->fields(new CompanyEmployeeFields())
->searchable(),
In CompanyEmployeeFields I have:
return [
Text::make('Title', 'title')->nullable(),
BelongsToMany::make('Role', 'roles', Role::class),
];
I see Company and Title when creating/editing the resource, but Role doesn't even show up or throw any errors in the logs.
Does anyone have an idea what might be going on?