dimanche 18 septembre 2016

Laravel 5 Validations

I want to validate my form fields using laravel 5. Form field 1 -> User ID : Form Field 2 -> Other Name :

Either of the form field is required. i mean if user id is present other name should be blank and if other name is present user_id should be blank.

I am trying to use:

$validator = Validator::make(
                            [
                        'user_id ' => $user_id,
                        'user_name' => $user_name
                            ], [
                        'user_id' => 'required_without:user_name',
                        'user_name' => 'required_without:user_id'
            ]);
            if ($validator->fails()) {
                return Utility::validation_err($validator);
            }

While updating record even if user id is present it gives me error user id is required when other name is not present. also if i am filling out both it accepts both ..it should accept one of both fields ..

Any help will be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire