sukohi/gazelle

对于此包的最新版本(dev-master)没有可用的许可信息。

dev-master 2015-07-06 09:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:55:45 UTC


README

这是一个主要为Laravel开发,用于管理验证器和轻松保存的PHP包。

使用方法

配置

在您的模型中,像以下这样设置GazelleTrait。

<?php

use Sukohi\Gazelle\GazelleTrait;

class Animal extends Eloquent {

    use GazelleTrait;

    protected $guarded = ['id'];

}

现在,您可以调用名为easyValidator()和easySave()的方法。

验证器

$validator = Animal::easyValidator([
    'name' => 'required',
    'count' => 'required|numeric|min:0',
]);

if($validator->fails()) {

    // Redirect or something here..

}

// with Attribute Name

$validator = Animal::easyValidator([
    'name' => ['required', 'Animal Name'],
    'count' => ['required|numeric|min:0', 'The Number of the Animals'],
]);

保存

// Insert
// In this case, Input::get('name') and Input::get('count') will saved.

Animal::easySave(['name', 'count']);


// Update

$id = 1;
Animal::easySave(['name', 'count'], $id);


// with Extra Data
// If "Input" has the same key, the value will be overwritten.

Animal::easySave(['name', 'count'], $id, [
    'name' => 'Springbok'
]);


$animal = Animal::easySave(['name', 'count']);  // You also can get instance. If save failed, return value is null.

许可证

此包根据MIT许可证授权。

版权所有 2015 Sukohi Kuhoh