How can i select the next to last record added to a table. I can select the last record like -
transition::order_by('created_at', 'desc')->first();
$lastUser = App\User::orderBy('created_at', 'desc')->first(); after you can update your model like this: $lastUser->name = "New Name"; $lastUser->save(); UPDATE: you can also use the id field instead of 'created_at' for ordering your data.
->latest() fetches the most recent set of data from the Database. In short, it sorts the data fetched, using the 'created_at' column to chronologically order the data.
skip() will help to skip some records when you fetch data from the database table. So, let's see bellow examples that will help you how to use take() and skip() eloquent query in laravel.
Try this:
transition::orderBy('created_at', 'desc')->skip(1)->take(1)->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With