tbence/validate

Automatic validation for laravel models.

v0.2.2 2017-08-31 20:32 UTC

This package is not auto-updated.

Last update: 2024-11-16 01:30:45 UTC


README

Total Downloads Latest Stable Version License

Adds an AutoValidation trait to your project. If you use that trait on your models, it will automatically vaildate it by your DB scheme. These validation rules can be overridden manually from the model.

Installation

composer require tbence/validate

If Laravel version < 5.5, you have to manually include this line in your config/app.php:

TBence\Validate\Provider::class,

Usage

Add the trait and the interface to your model. (Procuct is just an example.)

<?php

namespace App;

use TBence\Validate\AutoValidation;
use TBence\Validate\Validates;

class Product extends Model implements Validates
{
    use AutoValidation;
    
    //...
}

That's it. If you try to create or update a Product model with data that's not compatible with your database schema the package will throw a ValidationException which is handled by laravel automatically. So the system will not fail with something went wrong when you are missing a value for a not null column. It will return with standard validation error messages instead.

For example: The name field is required.

Warning

This package is still in early in development use it at your own risk!