padosoft/laravel-validable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

padosoft/laravel-validable

最新稳定版本:1.7.0

Composer 安装命令:

composer require padosoft/laravel-validable

包简介

Trait to activate validation when saving Eloquent Model

README 文档

README

Latest Version on Packagist Software License CircleCI Quality Score Total Downloads

This package provides a trait that will automatic handlind upload when saving/updating/deleting any Eloquent model with upload form request.

##Requires

  • php: >=7.0.0
  • illuminate/database: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
  • illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
  • illuminate/validation: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0

Installation

You can install the package via composer:

$ composer require padosoft/laravel-validable

Usage

Your Eloquent models should use the Padosoft\Laravel\Validable\Validable trait.

You must define protected static $rules array of rules in your model. You can define protected static $messages array of custom messages in your model.

Here's an example of how to implement the trait;

<?php

namespace App;

use Padosoft\Laravel\Validable\Validable;
use Illuminate\Database\Eloquent\Model;

class YourEloquentModel extends Model
{
    use Validable;
    protected static $rules = [
            'name'=>'required|max:10',
            'order'=>'sometimes|integer|max:10',
        ];
    
        protected static $messages = [
            'name.required'=>'obbligatorio'
        ];
}

You can write specific validation for only update method

class YourEloquentModel extends Model
{
    use Validable;
    protected static $rules = [
            'name'=>'required|max:10|unique:table,field',
            'order'=>'sometimes|integer|max:10',
        ];
    protected static $updating_rules = [
                'name'=>'required|max:10|unique:table,field,[id]',
                'order'=>'sometimes|integer|max:10',
            ];
        protected static $messages = [
            'name.required'=>'obbligatorio'
        ];
}

Note: [id] will be overwritten at runtime with the model property.

You can check if your model is saved like this:

$model = new YourEloquentModel;
$model->name='test';
if (!$model->save()){
    $erros=$model->getErrors();
}

You can get a model validation rules:

$rules=YourEloquentModel::getRules();

For all method available see the Validable Trait.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email instead of using the issue tracker.

Credits

Inspired by https://github.com/JeffreyWay/Laravel-Model-Validation

About Padosoft

Padosoft (https://www.padosoft.com) is a software house based in Florence, Italy. Specialized in E-commerce and web sites.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 11.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-16