Support the ongoing development of Laravel.io →
Architecture
Last updated 2 years ago.
0

Try

$def->save()

instead of

abc->def()->save($def);
Last updated 2 years ago.
0

The first line you were recalling the method for the relationship, this changes the Model back into a QueryBuilder instance so you can requery the database.

$def = $abc->def; 
$def->frequency = $fields['duration'];

$abc->def()->save($def);
Last updated 2 years ago.
0

I use $def->save(); instead of $abc->def()->save($def);

at that time i am getting this error.

Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, none given

Thanks HARSH SHAH

Last updated 2 years ago.
0

Maybe you have to create the def model before saving it

$def = New Def;
$def->frequency = $fields['duration'];

$abc->def()->save($def);

note that you need to know the $abc. But I see that you are creating it in

$abc=Abc::create($fields);

so it should be ok

Last updated 2 years ago.
0

Thank you so much TorchSK!!!!!! Keep It Up.......

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.