Welcome Guest, Not a member yet? Register   Sign In
Validation tutorial
#4

You are overriding your own validation that you have set in BaseController.

This are a stand alone function, that you pass your rules directly into that array.
$this->validate([])

If wan't to use setRules() you need to runt it like this:

if($this->validation->withRequest($this->request)->run()).

Here you can see the actual code that stand alone function executes.

PHP Code:
    /**
     * A shortcut to performing validation on input data. If validation
     * is not successful, a $errors property will be set on this class.
     *
     * @param array|string $rules
     * @param array        $messages An array of custom error messages
     *
     * @return boolean
     */
    
protected function validate($rules, array $messages = []): bool
    
{
        
$this->validator Services::validation();

        
// If you replace the $rules array with the name of the group
        
if (is_string($rules))
        {
            
$validation config('Validation');

            
// If the rule wasn't found in the \Config\Validation, we
            // should throw an exception so the developer can find it.
            
if (! isset($validation->$rules))
            {
                throw 
ValidationException::forRuleNotFound($rules);
            }

            
// If no error message is defined, use the error message in the Config\Validation file
            
if (! $messages)
            {
                
$errorName $rules '_errors';
                
$messages  $validation->$errorName ?? [];
            }

            
$rules $validation->$rules;
        }

        return 
$this->validator
            
->withRequest($this->request)
            ->
setRules($rules$messages)
            ->
run();
    } 
Reply


Messages In This Thread
Validation tutorial - by Codinglander - 04-22-2020, 10:48 PM
RE: Validation tutorial - by Leo - 04-23-2020, 02:51 AM
RE: Validation tutorial - by Codinglander - 04-23-2020, 03:17 AM
RE: Validation tutorial - by jreklund - 04-23-2020, 11:31 AM
RE: Validation tutorial - by Codinglander - 04-23-2020, 07:49 PM
RE: Validation tutorial - by jreklund - 04-24-2020, 09:40 AM
RE: Validation tutorial - by Codinglander - 04-24-2020, 11:12 AM
RE: Validation tutorial - by jreklund - 04-24-2020, 11:21 AM
RE: Validation tutorial - by hugoafr - 07-01-2020, 01:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB