This question already has an answer here:
- Laravel - Eloquent or Fluent random row 11 answers
I have a store and at product pages, the product is shown with ID (The latest product that is uploaded) but I wanna change to random.
$childs = \App\Category::where(['parent' => $cat->id])->orderby('id','desc')->get();
Full Code of the DIV below:
<div class="col-md-3">
<div class="form-group">
<select name="cat" class="form-control">
<option value=""><?=translate('Category')?></option>
<?php foreach($cats as $cat){
$selected = '';
if (isset($category->id)) {
$selected = ($category->id == $cat->id) ? 'selected' : '';
}
echo '<option value="'.$cat->id.'" '.$selected.'>'.translate($cat->name).'</option>';
$childs = \App\Category::where(['parent' => $cat->id])->orderby('id','desc')->get();
foreach ($childs as $child){
echo '<option value="'.$child->id.'" '.(isset($category->id) ? ($child->id == $category->id ? 'selected' : '') : '').'>- '.$child->name.'</option>';
}
}
?>
</select>
</div>
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire