$relation->save($model) method automatically fills in the appropriate foreign id, so you shouldn't need to set it.
I believe the issue here is you're using a
$user model that you got via dependency injection. That's going to be the general
User facade, not an instantiated model. Hence it probably doesn't have an
id, and when
save($task) gets called, it overrides the existing
$user->id, which is
Auth::user() returns a
User object, so you can just call this without fussing with any ids whatsoever:
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us