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

Well, first - You should provide Your solution a FormRequest, which might be as the following:


    namespace App\Http\Requests;

    use Illuminate\Support\Facades\Auth;

    /**
     * Class UserRequest
     * @package App\Http\Requests
     */
    class UserRequest extends Request
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return !Auth::check();
        }

        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'email' => 'required|unique:users|email_active:[email protected]|email_online:[email protected]',
                'password' => 'required|string|between:4,40'
            ];
        }

        public function messages()
        {
            return [
                'email.required' => 'Email is required',
                'email.unique' => 'This Email is already in use',
                'email.email_active' => 'This email is not active',
                'email.email_online' => 'This email is online',
                'password.required' => 'Password is required',
                'password.between' => 'Password length should be between :min and :max characters'
            ];
        }
    }

email_active and email_online rules don't exist on the Laravel box. You should create them via php artisan make:rule EmailActiveRule and php artisan make:rule EmailOnlineRule.

Then, You need to extend Your rules by following this article.

Then, in the rules You need to check the records in the database via Repository or Model

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.