jere rosas
jere rosas

Reputation: 111

print results in descending order

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

enter image description here

The problem is that it does not print with the foreach with the DESC order

Upvotes: 0

Views: 321

Answers (3)

Martin Sagat
Martin Sagat

Reputation: 49

You can use orderBy() as follows:

use App\Models\Eventos;

$servicios = Eventos::All()->orderBy('hora', 'DESC')->get();

Upvotes: 0

John Lobo
John Lobo

Reputation: 15319

Use orderByDesc

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

Upvotes: 1

Anna
Anna

Reputation: 119

Try this

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

Upvotes: 1

Related Questions