Support the ongoing development of Laravel.io →
posted 5 years ago
Requests
Last updated 2 years ago.
0

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',
            ],
        ];
    }
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Asim iteni iteniasim Joined 2 Nov 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.