find
Find is a simple static method used to find records by its model's primary key. It will either return the record if found, or else null
const user = await User.find(123)
select "users".* from "users"
where ("users"."id" = $1)
order by "users"."id" asc nulls first
limit 1
Chaining
Similar to other execution methods, find can be chained with other query building methods to filter at the sql level.
const user = await User.find(123)
select "users".* from "users"
where ("users"."id" = $1)
order by "users"."id" asc nulls first
limit 1
tip
In some cases, findOrFail may be more ideal, since it will raise a RecordNotFound exception, causing the request to fail with a 404 error automatically.