Skip to main content
When you retrieve Eloquent models from IDs submitted in a form, you can use the Form Request methods model, modelOrFail and models. Building on the requests guide, this page uses the implementation to clarify where these methods stop and input validation and authorization begin.

Retrieve the model after validation

For example, when an authenticated user picks a project of their team by ID, first validate the input format in a Form Request.
Inject this request into the controller from a route that uses the authentication middleware. This example assumes the application has a Project model and a view policy.
The Form Request is validated before the controller is called. When no matching record exists, modelOrFail throws a ModelNotFoundException, which normal HTTP handling turns into a 404. The team condition narrows the search, but it does not authorize the action on its own. Check the policy after retrieval as well.
These methods read the request input, not validated(). A Form Request’s authorize() runs before validation, so if you call model retrieval inside it, the input has not been validated yet. When you use input in authorize(), treat it as unvalidated and design the validation and authorization you need separately.

Return values and input differences

modelOrFail does not treat an array of IDs as the ID of a single model either. models does not throw when some IDs are not found; it returns only the matches. When every ID must exist and be actionable, validate the input array and its elements, compare the results with the input, and authorize each model. Do not assume the results come back in input order.

Query constraints and model inference

Retrieval starts from the model’s query(), so Eloquent global scopes also apply. The closure’s conditions are grouped in a where, and the primary key condition is added after it. This keeps OR conditions from leaking outside the ID condition, even when you use several orWhere calls. When you omit the class, Laravel strips _id / _ids from the input key, infers a singular class name, and looks in the application’s Models namespace, then the root namespace. When the names differ, such as author_id pointing to User, or when you work with a package’s model, pass the class explicitly, such as User::class. The lookup uses the model’s primary key, which is separate from the route key used by route model binding.
Last modified on November 29, 2026