lastOrFail
The lastOrFail method returns the last record found in the given table. If no record is found, a RecordNotFound exception is raised.
const user = await User.lastOrFail()
// User{id=9000}
select "users".* from "users" order by "users"."id" desc nulls last limit 1
Chaining
Similar to other execution methods, lastOrFail can be chained with other chainable query methods, such as order.
await User.order({ email: 'asc' }).lastOrFail()
select "users".* from "users" order by "users"."email" desc nulls last limit 1