How to get last record from table in PHP Laravel Framework?

How to get last record from table in PHP Laravel Framework?

In this example, I will tell you how to select last row from database table in Laravel with example.

There are several way to get last record from table in Laravel.

In PHP, you normally use order by clause with descending order to get last one record from database table and same you can do in laravel but laravel has some awesome method to interact with database table.

You can use latest method to get last record from database table in Laravel application.

Get last record from table using orderBy clause
  1. $last_row=DB::table('products')->orderBy('id', 'DESC')->first();

By running above command, record will be in descending order and you will get first row from record set of table.

Get last record from table using latest method
  1. $last_row = DB::table('products')->latest()->first();

By running above command, you will get last inserted record according to created_at column.

Phone: (+91) 8800417876
Noida, 201301
sakarya escort akyazı escort arifiye escort erenler escort eve gelen escort ferizli escort geyve escort hendek escort otele gelen escort sapanca escort söğütlü escort taraklı escort
escort bayan escort bayan escort bayan escort bayan escort bayan escort bayan escort bayan sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya serdivan escort sapanca escort karasu escort hendek escort izmir escort