Laravel 5 bundle for validate in models.
It's under development, not recommended for production use!
- add bundle to composer: "hlacos/modelValidation": "dev-master"
- composer install / update
- add service provider to the providers list: 'Hlacos\ModelValidation\ModelValidationServiceProvider'
In the rules array use the laravel validator formats.
class CustomModel extends Eloquent { use ModelValidationTrait; public $rules = array( 'attribute' => 'required', ); } $customModel = new CustomModel(); $customModel->setAttributes($attributes); if ($customModel->isValid()) { $customModel->save(); } else { return $customModel->errors; }