teepluss/harvey is a Laravel package for laravel4 separate validation.
It currently has 2 GitHub stars and 190 downloads on Packagist (latest version v1.0).
Install it with composer require teepluss/harvey.
Discover more Laravel packages by teepluss
or browse all Laravel packages to compare alternatives.
Last updated
This is my internal project, not yet complete.
To get the lastest version of Theme simply require it in your composer.json file.
"teepluss/harvey": "dev-master"
You'll then need to run composer install to download it and have the autoloader updated.
class Blog extends \Teepluss\Harvey\Harvey {
/**
* Define rules.
*
* @type array
*/
public static $rules = array(
'description' => 'min:10|max:500',
'onCreate' => array(
'title' => 'required',
'url' => 'active_url'
),
'onUpdate' => array(
'title' => 'required'
)
);
/**
* Custom validation messages.
*
* @type array
*/
public static $messages = array(
'title.required' => 'Please fill title before submitting.'
);
/**
* Custom validation labels.
* @type array
*/
public static $lables = array(
'title' => 'Title'
);
/**
* Construct.
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = array())
{
parent::__construct($attributes);
// Custom label.
$this->setLabelNames(array(
'title' => trans('labels.product'),
));
}
/**
* Event before validate.
*
* @return voide
*/
protected function beforeValidate()
{
$validator->sometimes('description', 'numeric', function($input)
{
return $input->title == 'tee';
});
}
}
$blog = new Blog;
$blog->title = 'New blog';
$blog->description = 'This is my first entry';
$blog->url = 'http://www.domain.com';
// Addition rule for another input.
$blog->addValidate(
array('other' => Input::get('other')),
array('other' => 'required|email'),
array('other.required' => 'sss')
);
if ( ! $blog->save())
{
$errors = $blog->errors();
return Redirect::back()->withErrors($errors)->withInput();
}
array(3) [
'description' => array(2) [
string (6) "min:10"
string (7) "max:500"
]
'title' => array(1) [
string (8) "required"
]
'url' => array(1) [
string (10) "active_url"
]
]
$blog = Blog::find(1);
$blog->title = 'New blog';
$blog->description = 'This is my first entry';
$blog->url = 'http://www.domain.com';
$blog->save();
if ( ! $blog->save())
{
$errors = $blog->errors();
return Redirect::back()->withErrors($errors)->withInput();
}
array(2) [
'description' => array(2) [
string (6) "min:10"
string (7) "max:500"
]
'title' => array(1) [
string (8) "required"
]
]
If you have some problem, Contact [email protected]