Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Retrieve only validated inputs from FormRequest #18665

Closed
wants to merge 2 commits into from
Closed

[5.4] Retrieve only validated inputs from FormRequest #18665

wants to merge 2 commits into from

Conversation

@timacdonald
Copy link
Contributor

@timacdonald timacdonald commented Apr 5, 2017

This allows you to call $this->validatedInputs() on Form Request objects and only retrieve inputs that have rules associated with them, i.e. only validated rules.

Helps keep in check that you are validating all the input that goes into your models as well I find.

This is something I do in my form objects just to make things that little nicer. Thought it might be helpful to others....maybe?

Example:

in a PostRequestForm class set your rules as per normal:

public function rules()
{
    return [
        'title' => 'required|string|max:30',
        'content' => 'required|string'
    ];
}

Then in your controller you can just call:

public function store(PostRequestForm $form)
{
    Post::create($form->validatedInputs());
}

For pretty simple rules, this is great, but might not work so well for more complex rules such and open to suggestions for making it work well with these kind of rules.

'users.*.email' => 'required|email'
@timacdonald timacdonald changed the title 5.4 Retrieve only validated inputs from FormRequest [5.4] Retrieve only validated inputs from FormRequest Apr 5, 2017
@antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Apr 5, 2017

Interesting idea

@taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Apr 5, 2017

Hmm, it's a neat idea. Might let you just define it on your own form requests but I'll keep it in mind for the future. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants