I want to select all rows from a mysql table except for the most recent one by using Eloquent in Laravel. I currently do this to get the most recent entry only, but wish to do the reverse:
Table::orderBy('created_at', 'desc')->first();
Any idea how I do this?
You can make use of laravel collections shift method.
$data = DB::table('your_table')->orderBy('created_at', 'desc')->get();
$data->shift(); //which removes the first element. now $data has all other values except for first one.
you can simply skip the first one from the results:
Table::orderBy('created_at', 'desc')->skip(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