To add a new validation to Laravel I have done this:
made a new file called customValidation.php
in app/start/
and then included it in
I would create custom app/validators
folder for this then.
1, Create app/validators/CustomValidate.php
<?php
class CustomValidate extends Illuminate\Validation\Validator
{
public function validateCheckbox($attribute, $value, $parameters)
{
echo "this is the: " . $value;
}
}
2, run php artisan optimize
or composer dumpautoload
3, Somewhere register your custom validator. Perhaps add app/validators.php
into start/global.php
Validator::resolver(function($translator, $data, $rules, $message){
return new CustomValidate($translator, $data, $rules, $message);
});
4, Validate
$rules = ['agreed' => 'checkbox'];
$data = ['agreed' => 0];
$v = Validator::make($data, $rules);
dd($v->passes());
When submitting the form, the radios were not set in their initial states, and this made Laravel not to look for the validator of the item. So, it doesn't have any workaround for that. What I did was I simply added an initial state to the radios and they worked.
Much Like said by Andreyco