Skip to content

Latest commit

 

History

History
executable file
·
30 lines (23 loc) · 810 Bytes

readme.md

File metadata and controls

executable file
·
30 lines (23 loc) · 810 Bytes

hot-cover

1, Create app/validators/CustomValidate.php

<?php

class CustomValidate extends Illuminate\Validation\Validator
{

public function validateYoutubeUrl($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 in model:

$rules = ['content'=>'required|youtube_url'];

5, In model: public static $messages = array('youtube_url' => 'hello');
6. In controller: $validation = Validator::make($input, Post::$rules, Post::$messages);