定制 ognjen/laravel-validatable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ognjen/laravel-validatable

最新稳定版本:v1.0.1

Composer 安装命令:

composer require ognjen/laravel-validatable

包简介

Validate eloquent model

README 文档

README

Validate eloquent model before saving.

Install

Require package with Composer:

composer require ognjen/laravel-validatable

Usage example

Define validation rules and messages on the model itself.

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Ognjen\Laravel\Validatable;

class User extends Model {
    use Validatable;

    const VALIDATION_MESSAGES = ['age.numeric'=> 'Custom numeric message'];
    protected $fillable = ['name', 'email', 'age'];
    
    protected function getValidationMessages()
    {
        return self::VALIDATION_MESSAGES;
    }

    protected function getValidationRules()
    {
        return [
            'name' => 'required',
            'email'=> 'required|email|unique:users,email',
            'age'=> 'required|numeric'
        ];
    }
}
$user = User::create([
    'name' =>'name',
    'email'=>'name@example.com',
    'age' => 66
]);

if ($user->hasValidationErrors())
{
    $user->getValidationErrors();
}  
$user = new User();
$user->name = 'name';
$user->email = 'name@example.com';
$user->age = 'not a numeric';

if ($user->save() === false)
{
    $user->getValidationErrors();
}     

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-17