public function assignedUsers()
{
return $this->morphToMany(User::class, 'assignable', 'assignables', 'assignable_id', 'assigned_id')
->where('assigned_type', User::class);
}
public function assignedTeams()
{
return $this->morphToMany(Team::class, 'assignable', 'assignables', 'assignable_id', 'assigned_id')
->where('assigned_type', Team::class);
}
I have to do like this to make it work.
$p->assignedUsers()->attach($u, ['assigned_type' => User::class]);
what am i doing wrong? shouldn't it know assigned_type? 😭😭
if i do without manually filling out attribute, it gives me
SQLSTATE[HY000]: General error: 1364 Field 'assigned_type' doesn't have a default value (Connection: mysql, SQL: insert into assignables (assignable_id, assignable_type, assigned_id, created_at, updated_at) values (1, App\Models\Project, 1, 2024-08-24 11:33:58, 2024-08-24 11:33:58)).