Package Data | |
---|---|
Maintainer Username: | markeilander |
Maintainer Contact: | mark.eilander@outlook.com (Mark Eilander) |
Package Create Date: | 2016-02-16 |
Package Last Update: | 2018-09-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:03:56 |
Package Statistics | |
---|---|
Total Downloads: | 144 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
[TOC]
This package is based on laravel validation: http://laravel.com/docs/5.1/validation
use Eilander\Validator\LaravelValidator as Validator;
class UpdateUserValidator extends Validator
{
protected static $rules = [
'name' => 'required',
'email' => 'required|email',
'msg' => 'required'
];
}
You may use custom error messages for validation instead of the defaults http://laravel.com/docs/5.1/validation#working-with-error-messages
protected static $messages = [
'required' => 'The :attribute field is required.',
];
Or, you may wish to specify a custom error messages only for a specific field.
protected static $messages = [
'email.required' => 'We need to know your e-mail address!',
];
use \Eilander\Validator\Exceptions\ValidatorException;
class PostsController extends BaseController {
/**
* @var PostRepository
*/
protected $repository;
/**
* @var PostValidator
*/
protected $validator;
public function __construct(PostRepository $repository, PostValidator $validator){
$this->repository = $repository;
$this->validator = $validator;
}
public function store()
{
if ($this->validator->fails($request->all())) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
// do something
}
}