Prakhar Singh Prakhar Singh - 15 days ago 6
MySQL Question

Select second last record with Laravel - eloquent

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();

Answer

Try this:

transition::orderBy('created_at', 'desc')->skip(1)->take(1)->get();