定制 moh4mmad/request-validation-generator 二次开发

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

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

moh4mmad/request-validation-generator

最新稳定版本:v1.0.2

Composer 安装命令:

composer require moh4mmad/request-validation-generator

包简介

A package to generate request validation files based on migration column data types, column lengths, uniqueness, and foreign keys.

README 文档

README

Request Validation Generator is a Laravel package that automatically generates request validation files based on your migration column data types, column lengths, uniqueness, and foreign keys.

Installation

You can install the package via Composer. Run the following command:

composer require moh4mmad/request-validation-generator

After installing the package, you need to publish the configuration file and migration files. Run the following command to publish the package assets:

php artisan vendor:publish --tag=request-validations

This command will publish the package's configuration file and migration files to your application, allowing you to customize the behavior and modify the generated request validation files if needed.

Usage

To generate request validation files for your migrations, run the following Artisan command:

php artisan generate:request-validations

The command will scan your migration files and generate request validation files based on the column data types, lengths, uniqueness, and foreign keys. The generated files will be placed in the app/Http/Requests directory.

Example

Let's say you have a migration file 20220101000000_create_users_table.php with the following columns:

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->timestamps();
});

Running the generate:request-validations command will generate a request validation file app/Http/Requests/User/Request.php with the following content:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' => ['required', 'string'],
            'email' => ['required', 'string', 'email', 'unique:users,email'],
            'password' => ['required', 'string'],
        ];
    }
}

The generated request validation file provides the validation rules for each column in the migration. You can use this file in your controllers or form requests for validating incoming requests.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This package is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固