Answer the question
In order to leave comments, you need to log in
How to properly update related models using Resource in Laravel?
There are 2 models - User and Country. Country_id is stored in the User model, they are linked by this key.
Made UserResource
return [
'id' => $this->id,
'name' => $this->name,
'country' => $this->country->eng_name
];
Answer the question
In order to leave comments, you need to log in
Update better in controllers.
For example. Country_id is passed from the view to the controller along with other data. Then in the controller, in the store method
or
You can give the relationship object through the resource like this
return [
// Отношения
'country' => new CountryResource($this->country)
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question