mawuekom/laravel-request-customizer

自定义 Laravel 表单请求

v1.2.1 2022-04-21 14:12 UTC

This package is auto-updated.

Last update: 2024-09-21 19:32:33 UTC


README

此包为 Laravel 项目提供自定义表单请求。它还包括表单数据清理和 API 表单请求扩展

安装

您可以通过 composer 安装此包

composer require mawuekom/laravel-request-customizer

用法

您可以使用如下方式...
对于清理器,请查看Laravel Request Sanitizer 以获取更多信息

namespace App\Http\Requests;

use Mawuekom\RequestCustomizer\FormRequestCustomizer;

class CreateUserRequest extends FormRequestCustomizer
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'name'          => 'required|string|max:255',
            'first_name'    => 'required|string|max:255',
            'email'         => 'required|string|email|max:255|unique:users',
            'password'      => 'required|string|min:6|confirmed',
        ];
    }

    /**
     * Get sanitizers defined for form input
     *
     * @return array
     */
    public function sanitizers(): array
    {
        return [
            'name' => [
                Capitalize::class,
            ],
            'first_name' => [
                CapitalizeEachWords::class
            ]
        ];
    }
}

测试

composer test

变更日志

请参阅CHANGELOG 了解最近更改的详细信息。

贡献

请参阅CONTRIBUTING 了解详细信息。

安全性

如果您发现任何安全相关问题,请通过seddorephraim7@gmail.com 发送电子邮件,而不是使用问题跟踪器。

许可

MIT 许可证 (MIT)。请参阅许可文件 了解更多信息。