jeudi 27 mai 2021

Combine laravel queries

Is it possible to combine those queries in one? What I need is to get 4 rows spaced by 6 hours from now.

$data1 = TransacoesRecentes::orderBy('created_at', 'desc')
        ->whereRaw('created_at <= NOW() - INTERVAL 24 HOUR')
        ->first();

$data2 = TransacoesRecentes::orderBy('created_at', 'desc')
        ->whereRaw('created_at <= NOW() - INTERVAL 18 HOUR')
        ->first();

$data3 = TransacoesRecentes::orderBy('created_at', 'desc')
        ->whereRaw('created_at <= NOW() - INTERVAL 12 HOUR')
        ->first();

$data4 = TransacoesRecentes::orderBy('created_at', 'desc')
        ->whereRaw('created_at <= NOW() - INTERVAL 6 HOUR')
        ->first();

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire