Reputation: 111
I need to print results in a decreasing way
controller:
$servicios = \App\Models\Eventos::All()->sortByDesc('hora');
blade.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
The problem is that it does not print with the foreach with the DESC order
Upvotes: 0
Views: 321
Reputation: 49
You can use orderBy() as follows:
use App\Models\Eventos;
$servicios = Eventos::All()->orderBy('hora', 'DESC')->get();
Upvotes: 0
Reputation: 15319
Use orderByDesc
$servicios = \App\Models\Eventos::orderByDesc('hora')->get();
Upvotes: 1