dimanche 26 août 2018

ORDER BY RANDOM (PHP) [duplicate]

This question already has an answer here:

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>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NobBqk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire