Reputation: 1494
I am unable to assign a value to a model's property
App\person::find(1)->plan
This command gives me something like this in artisan tinker
id: 1,
name: "name",
description:"",
I am trying to specify a value for description
App\person::find(1)->plan->description='something'
It outputs
'something'
But it's not saving it in the description, I still get this
id: 1,
name: "name",
description:"",
I tried several commands, none work
App\person::find(1)->plan->description='something'->save();
App\person::find(1)->plan->description->save('something');
Am I doing it wrong? Yes, the model's property has been set to fillable
Upvotes: 1
Views: 1316
Reputation: 622
To save you have to
$person= App\person::find(1);
$person->plan->description='something';
$person->plan->save();
Or if you need a one liner do
App\person::find(1)->plan->fill(['description' => 'something')->save();
.
The way you did will try to execute save on a string:
App\person::find(1)->plan->description='something'->save();
Upvotes: 5
Reputation: 3908
Try like this:
$plan = App\person::find(1)->plan;
$plan->description = 'something';
$plan->save();
Upvotes: 0