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

Not sure which validation you're after but for example if you'd like to validate how many inputs are filled, as a quick test you could use this in your controller/route:

        Validator::extend('requireAll', function($attribute, $values, $parameters)
        {
            $countFilled = count(array_filter($values));
            return ($countFilled == count($values));
        });
        Validator::extend('requireMin', function($attribute, $values, $parameters)
        {
            $countFilled = count(array_filter($values));
            return ($countFilled >= $parameters[0]);
        });
        Validator::extend('requireMax', function($attribute, $values, $parameters)
        {
            $countFilled = count(array_filter($values));
            return ($countFilled <= $parameters[0]);
        });
        Validator::extend('requireBetween', function($attribute, $values, $parameters)
        {
            $countFilled = count(array_filter($values));
            return ($countFilled >= $parameters[0] && $countFilled <= $parameters[1]);
        });
        $v = Validator::make(Input::all(), ['time_slot_start' => 'requireBetween:2,3']);

        if ($v->fails())
        {
            return $v->errors();
        }

        return 'success!';

this example validates that 2 or 3 inputs are filled.

For a cleaner solution, I would recommend extending the Validator class and declare your custom rules and error messages in it For more info, see the validation in the laravel docs

Last updated 2 years ago.
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.