I have three tables and a pivot table:
Company
roleuserable_id
roleuserable_type
User
user_id
Role
role_id
Starting from the company i have relationship
public function roles()
{
return $this->morphToMany('App\Role', 'roleuserable', 'role_user')->withPivot('user_id');
}
How can i achieve something similar to this knowing that the block below will result with an error:
// The company
$company = Company::first();
// Sync data
$data = [
1 => [[user_id => 1], [user_id=>2]],
2 => [[user_id => 1], [user_id => 3]]
];
// Data sync
$company->roles()->sync($data);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire