Hello,
Hmmm ... I have this code.
public function index()
{
return Inertia::render('Creator/Quests/Index', [
'quests' => fn () => Quest::orderBy('name')->get()->toResourceCollection(),
]);
}
When I check in the backend (with dd()) the content of the query, it returns only the quests without any step as the steps aren't loaded.
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'code' => $this->code,
'qrcode' => $this->qrcode,
'synopsis' => $this->synopsis,
'location' => $this->location,
'coordinates' => $this->coordinates,
'duration' => $this->duration,
'participants_min' => $this->participants_min,
'participants_max' => $this->participants_max,
'level' => $this->level,
'state' => [
'value' => $this->state->value,
'label' => $this->state->label(),
'color' => $this->state->color(),
],
'calculated_distance' => $this->calculated_distance,
'calculated_duration' => $this->calculated_duration,
'user_id' => $this->user_id,
'steps' => StepResource::collection($this->whenLoaded('steps')),
'medias' => MediaResource::collection($this->whenLoaded('medias')),
];
}
But in the frontend, I see all steps for each quest.
I have checked everywhere in my code and I never load the steps, I don't call the steps with $quest->steps, ...
It's strange.
Why do I retrieve the steps without loading them explicitely ?
Is there any implicit eager loading for the relationships in API mode ?
Thanks for your help to understand what happens.
V