承接 php-soft/laravel-base 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

php-soft/laravel-base

Composer 安装命令:

composer create-project php-soft/laravel-base

包简介

The Laravel Framework.

README 文档

README

Build Status

Somes utilities for Laravel 5.x

  1. Middleware convert input camelCase to snakecase
  2. Middleware validate

I. Installation

Install via composer - edit your composer.json to require the package.

"require": {
    // ...
    "php-soft/laravel-base": "dev-master",
}

Then run composer update in your terminal to pull it in. Once this has finished, you will need to add the service provider to the providers array in your app.php config as follows:

'providers' => [
    // ...
    PhpSoft\Base\Providers\BaseServiceProvider::class,
]

II. Usage

1. Middleware convert input camelCase to snakecase

To use the middlewares you will have to register them in app/Http/Kernel.php under the $routeMiddleware property:

protected $routeMiddleware = [
    ...
    'camelToSnake'       => \PhpSoft\Base\Middleware\CamelToSnake::class,
];

Add routes in app/Http/routes.php

Route::group(['middleware'=>'camelToSnake'], function() {

   // Your route
});

2. Validate

This middleware is used to check validate for fields on different applications which use this package.

Add route middlewares in app/Http/Kernel.php

protected $routeMiddleware = [
    // ...
    'validate'   => \PhpSoft\Base\Middleware\Validation::class,
];

Usage

Route::post('/user', ['middleware'=>'validate: App\Http\Validators\UserValidate',
    function () {
        //
    }
]);

With App\Http\Validators\UserValidate, it's class which you need to declare in route. This class is used to declare rules to validate.

You can also use other class to declare rules for validate in your application but It have to implements PhpSoft\Base\Validation\Contract class.

For example, I declared rules in App\Http\Validators\UserValidate class as follows:

use PhpSoft\Base\Validation\Contract;

/**
 * User Validate
 *
 * return array
 */
class UserValidate implements Contract
{
    /**
     * Custom validator
     * 
     * @return boolean
     */
    public static function boot($request)
    {

        IlluminateValidator::extend('validate_name', function($attribute, $value, $parameters) {

                return $value == 'validate_name';
            }, 'The name is in valid.'
        );
    }

    /**
     * Declare rules
     * 
     * @return array
     */
    public static function rules()
    {
        return [
            'name'     => 'required|max:255|validate_name',
            'email'    => 'required|email',
            'password' => 'required|confirmed|min:6'
        ];
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固