Route model binding loads a model from a URL segment, but sometimes you need to load a model (or multiple) through a request body. A form that assigns a task might send an assignee_id and a list of label_ids. You validate those IDs using a FormRequest instance, then query for the same records again in the controller. When the records belong to a team, the team condition has to appear in both places.
Starging in Laravel 13.44, you can use three new form request methods for loading models from input: model(), modelOrFail(), and models(). To see how they work, let's look at an example and rewrite it one step at a time to use these methods:
Validating and Loading the Same IDs
Here is the form request before the change. Each exists rule checks that the ID belongs to the current user's team:
public function rules(): array { $teamId = $this->user()->team_id; return [ 'assignee_id' => ['required', Rule::exists('users', 'id')->where('team_id', $teamId)], 'label_ids' => ['array'], 'label_ids.*' => [Rule::exists('labels', 'id')->where('team_id', $teamId)], ]; }
The controller then loads the records that validation already found:
public function update(AssignTaskRequest $request, Task $task) { $teamId = $request->user()->team_id; $assignee = User::where('team_id', $teamId)->findOrFail($request->integer('assignee_id')); $labels = Label::where('team_id', $teamId)->findMany($request->array('label_ids')); $task->assignee()->associate($assignee); $task->save(); $task->labels()->sync($labels); return to_route('tasks.show', $task); }
The code works, but it queries for each record twice and repeats the team condition in the rules and in the controller.
Load a Model From Input
Let's tart with updating the controller. You pass the new methods an input key and a model class, and they run the query for you:
$assignee = $request->modelOrFail('assignee_id', User::class); $labels = $request->models('label_ids', Label::class);
The modelOrFail() method returns the User, or throws a ModelNotFoundException when no record matches. The models() method reads an array of IDs and returns an Eloquent collection.
The third method, model(), is for input that is optional. It returns null when the ID is missing or no record matches. If the form had an optional reviewer, you could write:
$reviewer = $request->model('reviewer_id', User::class);
Let Laravel Pick the Model Class Through Conventions
You can leave out the model class when the input key matches the model name. Laravel removes _id or _ids from the end of the key, makes the rest singular, and converts it to StudlyCase. It then looks for that class in App\Models, and falls back to the App namespace.
In our form, label_ids resolves to App\Models\Label, so the class can go:
$labels = $request->models('label_ids');
The assignee_id key is different. Laravel guesses from the key name and knows nothing about your relationships, so it looks for an Assignee class that doesn't exist, which is why the User::class is needed on that call.
Scope the Lookup to a Team
So far the lookups load any user and any label, including records from another team. Each method accepts a closure that receives the Eloquent query, and this is where the team condition goes:
$assignee = $request->modelOrFail('assignee_id', User::class, fn ($query) => $query ->where('team_id', $request->user()->team_id) ); $labels = $request->models('label_ids', fn ($query) => $query ->where('team_id', $request->user()->team_id) );
The closure is the third argument when you pass a class, and the second when you let Laravel determine the model. Laravel wraps your conditions in a group before it adds the ID condition, so an orWhere() in the closure can't bypass the ID match.
A record outside the scope is treated as missing. With modelOrFail() that means an exception, and with model() it means null.
Move the Lookups Into the Form Request
The controller is shorter now, but the team condition is still written twice. Since the helpers live on the form request, you can put the lookups there as methods and define the scope once:
namespace App\Http\Requests; use App\Models\User; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Http\FormRequest; class AssignTaskRequest extends FormRequest { public function rules(): array { return [ 'assignee_id' => ['required', 'integer'], 'label_ids' => ['array'], 'label_ids.*' => ['integer'], ]; } public function assignee(): User { return once(fn () => $this->modelOrFail('assignee_id', User::class, $this->forTeam(...))); } public function labels(): Collection { return once(fn () => $this->models('label_ids', $this->forTeam(...))); } protected function forTeam($query): void { $query->where('team_id', $this->user()->team_id); } }
The rules now check only the shape of the input, and the scoped lookups decide whether a record is allowed. The helpers don't cache their results, so each call runs a query. Wrapping them in once() means a second call to assignee() in the same request returns the same model.
The controller now calls those two methods:
public function update(AssignTaskRequest $request, Task $task) { $task->assignee()->associate($request->assignee()); $task->save(); $task->labels()->sync($request->labels()); return to_route('tasks.show', $task); }