I am using laravel and i need to retrieve the last row of my table. I'm using the code below but apparently it is getting the whole table and then looping to the last element . This would become an issue if the table is huge.
$result = Table::orderBy('created_at', 'desc')->first();
Is there a better , more efficient way to get the last row : Eloquent or sql query.
Thanks
first()
will create a query with the limit of one because it knows you only want one element. – cre8