首页 > 解决方案 > 按降序打印结果

问题描述

我需要以递减的方式打印结果

控制器

$servicios = \App\Models\Eventos::All()->sortByDesc('hora');

刀片.php

@foreach ($servicios as $hoy)
    <tr>
        <td class="checkbox-column text-center">{{$hoy->id}} </td>
        <td>{{$hoy->hora}}</td>
        <td>{{$hoy->titulo}}</td>
        <td>{{$hoy->personal}}</td>
        <td>{{$hoy->servicio}}</td>
        <td>{{$hoy->descripcion}}</td>
        <td class="text-center">
            <span class="shadow-none {{$hoy->prioridad}}">
                @if($hoy->prioridad == 'badge badge-primary') 
                    Normal
                @elseif($hoy->prioridad == 'badge badge-warning') 
                    Prioridad
                @elseif($hoy->prioridad == 'badge badge-success') 
                    Personal
                @elseif ($hoy->prioridad == 'badge badge-danger') 
                    Urgente
                @endif
            </span>
        </td>
    </tr>
@endforeach

在此处输入图像描述

问题是它不使用带有 DESC 顺序的 foreach 打印

标签: laravellaravel-5laravel-8

解决方案


尝试这个

$servicios = \App\Models\Eventos::latest('hora')->get();

推荐阅读