Support the ongoing development of Laravel.io →
Laravel Requests Validation
Last updated 1 month ago.
0

The request validate function directly validate the input. If it fails it will throw an exception that is by default handled. (You can catch it and do your own validation)

The return value of the validate function is the data

See: https://laravel.com/docs/8.x/validation#quick-writing-the-validation-logic

public function registerPost(Request $request)
    {
        $validData = $request->validate([
            'rname' => 'required|min:3|max:20|alphaspace',
            'rlastname' => 'required|min:3|max:30|alphaspace',
            'remail' => 'required|email|unique:users,email',
            'password' => 'required|min:8|confirmed',
            'password_confirmation' => 'required',
        ]);

        //here can you do something with the validData
        //$validData
    }
0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.