vendredi 14 décembre 2018

Laravel query sql

Good night. I am trying to get back the latest and only 1 item from the database. But the problem is 3 items were entered in the database at the same time. So the date is the exact same down to the seconds. How do i get the latest by the created_at date and the ID that is >

See what i have below that was giving the problem:

$latest = $newInv->where('case_number', $request-> case_number)
    ->orderBy('created_at', 'DESC')
    ->latest()->first();

What i was hoping to do but still fails how do i write this better maybe?

$latest = $newInv->where('case_number', $request->case_number)
        ->orderBy('created_at', 'DESC')
        ->orderBy('id', 'ASC')
        ->latest()->first();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire