First's of all it's a really bad practice to perform queries inside your views. There are better ways of doing this.
The reason your code doesn't return anything is probably that the query return an empty result. What is $subCatg here?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
@foreach($mainCatg->get() as $m)
{{$m->catg_name}}
@foreach($subCatg->where('catg_name',$m->catg_name)->get() as $s)
{{$s->catg_name}}
@endforeach
@endforeach
I have an issue with this code. I didn't get the result of the 2nd loop. It just shows empty.
First's of all it's a really bad practice to perform queries inside your views. There are better ways of doing this.
The reason your code doesn't return anything is probably that the query return an empty result. What is $subCatg here?
Please or to participate in this conversation.