Answer the question
In order to leave comments, you need to log in
How to limit fetch depth in Laravel?
Good day colleagues, tell me how in Laravel 7 you can limit the selection of a tree structure, the essence of the idea is that users simply register under each other like in affiliate programs. I took recursive output as a basis.
In my model
public function children()
{
return $this->hasMany(User::class);
}
public function childrenRef(){
return $this->hasMany(User::class)->with('children');
}
$users = User::where('user_id', 1)->with('childrenRef')->get();
@if ($loop->depth >= 3)
@break
@else
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question