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

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!

Eventy

Your banner here too?

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.