Selecting last row of a table

It can be done using latest() method. Here function parameter can be empty or it can have field name upon which sorting will be descending. Example below

// last row sorted descending with ID with empty parameter
Post::latest()->first()
//or last row sorted descending by given field name which is given title here
Post::latest('title')->first()

Related Posts


Using WhereIn

Updating multiple rows

Using Like

Using orWhere

What is Query Builder?

Using "with" in eloquent query

Getting last inserted id

Using parameters in find() method

Using local scope in eloquent

Using global scope in eloquent