Cách lấy last record of database table trong Laravel
Trong dự án nhiều khi chúng ta muốn lấy bản ghi cuối cùng trong 1 table nào đó.
Để giải quyết vấn đề này chúng ta có thể sử dụng hàm latest() hoặc orderBy() trong Laravel 6+.
Mình sẽ demo 3 cách lấy bản ghi cuối cùng trong table ở các ví dụ bên dưới nhé.
Đầu tiên mình sẽ tạo một table items có các dữ liệu demo như bên dưới.
Using latest() belong to created_at field:
Khi sử dụng latest() mặc định nó...
Laravel
2188