laravel - 按降序打印结果
问题描述
我需要以递减的方式打印结果
控制器:
$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 打印
解决方案
尝试这个
$servicios = \App\Models\Eventos::latest('hora')->get();
推荐阅读
- python - Python初学者刽子手麻烦
- javascript - 为什么在我这样做之前jquery拖动不起作用
- flutter - 如何在函数内使用 setstate 返回一个小部件?
- android - Kotlin:尝试将以下函数添加到全局共享文件以用于多个活动但不断收到不同的错误
- javascript - 简单 for 循环的令人困惑的结果
- java - 如何按顺序运行 2 个 .java 类?(带有 Eclipse 的硒)
- python - 如何解决 PyAudio 安装错误
- c# - Asp.Net Core - Identity SignInManager - 如何使用附加条件登录以便用户登录(例如:ClientId、UserName 和 Password))
- jquery - 如何运行 setTimeout() 直到特定事件?
- sql - NULL 或零金额的合并等价物