2

In the below function, $input['num_opt'] cannot access $input

$input = $request->all();

        $validator->after(function($validator) {
            $num_opt = $input['num_opt'];
            if ($this->isValidOpt($num_opt)) {
                $validator->errors()->add('num_opt', 'Something is wrong with this field!');
                echo 'test';        
            }
        });

what is the best practice to pass $input inside the function.

hkguile
  • 4,235
  • 17
  • 68
  • 139

1 Answers1

7

A closure has the use language construct to pass variables from parent scope.

function($validator) use ($input) {
Federkun
  • 36,084
  • 8
  • 78
  • 90