jeudi 29 novembre 2018

Laravel updating Model Fails because of relationship

I have a situation where I fetch a model in Laravel. Something like this:

$user = User::with('subscription')->where('id', '=', 123)->first();

If I then later try and do something like this:

$user->firstname = 'John';
$user->save();

I get an SQL error because it says that there is no DB field called "subscription" It seems like the relationship is being treated as a DB field when saving. Is that right? Am I mean to

unset($user->subscription)

before saving?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire