hlacos/model_validation

There is no license information available for the latest version (dev-master) of this package.

dev-master 2015-06-02 15:12 UTC

This package is auto-updated.

Last update: 2022-09-13 18:39:38 UTC


README

Laravel 5 bundle for validate in models.

It's under development, not recommended for production use!

Installation

  1. add bundle to composer: "hlacos/modelValidation": "dev-master"
  2. composer install / update
  3. add service provider to the providers list: 'Hlacos\ModelValidation\ModelValidationServiceProvider'

Usage

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;
}