I have 2 Models(Category and Company) with relationship between them. I want to show random Companies. How to use inRandomOrder/shuffle() in subquery.
I tried this. But it shuffle Category, but not Companies. I need opposite.
$categoriesAll = \App\Category::all()->shuffle();
My view looks like this:
@foreach ($categoriesAll as $categoryAll)
<div class="header">
<i class=" icon-bg-"></i>
<h4></h4>
</div>
<ul class="category-list" >
<?php $j= 0; ?>
@foreach ( $categoryAll->companies as $singleCompany)
<li><a href="category.html"> </a></li>
<?php if (++$j == 4) break; ?>
@endforeach
</ul>
<?php if (++$i == 8) break; ?>
Thank you for your help.
Aucun commentaire:
Enregistrer un commentaire