Answer the question
In order to leave comments, you need to log in
How to reduce the number of requests?
Hello, tell me how to properly organize the code and reduce the number of requests?
I have a certain model, let it be called "Model 1"
there is still a model, let it be called "Model 2" and it is a child of "Model 1"
there is still a model, let it be called "Model 3" and it is a child of "Model 2" "
Or for the subject area
- Model "Agreement 1"
- Model "Node 2"
- Model "Equipment 3"
- Model "Node 2"
- Model "Other Equipment 3"
an approximate such structure, nesting can be 3-4 levels
All these models are linked by hasOne\hasMany\BelongsTo... relays.
this is how the resource for the Contract is displayed (top level)
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
..........
'unit' => UnitResource::collection($this->units), // тут выводим все узлы догоовра
];
}
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
..........
'unit' => EquipmentResource::collection($this->units), // тут выводим все оборудование для Узла
];
}
Answer the question
In order to leave comments, you need to log in
Perhaps the best solution would be to use raw requests with a bunch of joins, they are easier to control and less overhead
so that there are no extra / duplicate requests?
read about eager loading with whenLoaded (cool
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question