eloquent - Laravel select last row on database table -
i want last file inserted in table. know method 'first' provides first file in table don't know how last insert.
thx.
you'll need order same field you're ordering now, descending. example, if have time stamp when upload done called upload_time
, you'd this;
for pre-laravel 4
return db::table('files')->order_by('upload_time', 'desc')->first();
for laravel 4 , onwards
return db::table('files')->orderby('upload_time', 'desc')->first();
this order rows in files table upload time, descending order, , take first one. latest uploaded file.
Comments
Post a Comment