With the first method, Laravel can automatically inject an appropriate type of request, which can have different properties. Mostly this is useful for route and method specific validation.
If you have
public function update(ProjectUpdateRequest $request, Project $project)
{
$project->title = $request->input('title');
$project->save();
return redirect('/projects');
}
You can than have a ProjectUpdateRequest
class with rules just for a Project when it's being updated.
class ProjectUpdateRequest extends FormRequest
{
public function rules()
{
return [
'name' => [
'required',
'max:255',
],
];
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community