urameshibr/lumen-form-request

Laravel Form Request 对 Lumen 框架的适配。

1.6.1 2022-11-08 17:10 UTC

This package is auto-updated.

Last update: 2024-09-22 13:40:48 UTC


README

Laravel Form Request 对 Lumen 框架的适配

您愿意通过购买我一杯咖啡来鼓励我吗?

Donate

如何安装

Lumen 9 (需要 php >= 8.0)

对于 Lumen 9 项目,该包在版本 1.6+ 上自动打上标签。

  • 步骤 1 - 在您的项目中安装包
composer require urameshibr/lumen-form-request
  • 步骤 2 - 在 bootstrap/app.php 中添加服务提供者
$app->register(Urameshibr\Providers\LumenFormRequestServiceProvider::class);

注意:当前包的版本有一个新的提供者名称,如果您正在更新,您必须更新 bootstrap/app.php 文件中提供者名称的使用。

  • 步骤 3 - 添加包所需配置文件。

在根项目文件夹中,运行以下命令以创建所需的配置文件

php vendor/urameshibr/lumen-form-request/src/run/add-session-config.php

在此命令之后,将在您的项目文件夹中创建一个名为 config/session.php 的文件。

下一步是创建您的 FormRequest 并从 Urameshibr/Requests/FormRequest 继承,如下例所示

<?php

namespace App\Http\Requests;

use Urameshibr\Requests\FormRequest;

class StoreProductRequest extends FormRequest
{
	public function authorize(): bool
	{
		return true;
	}

	public function rules(): array
	{
		return [
		    // your validation rules
		];
	}
}
  • Laravel Form Request 文档链接

https://laravel.net.cn/docs/9.x/validation#available-validation-rules

旧版本

Lumen 5.5 (需要 php >= 5.6)

composer require urameshibr/lumen-form-request:1.4

Lumen 5.6+ (需要 php >= 5.6)

composer require urameshibr/lumen-form-request:1.5
  • 在 bootstrap/app.php 中添加服务提供者
$app->register(Urameshibr\Providers\FormRequestServiceProvider::class);

下一步是创建您的 FormRequest 并从 Urameshibr/Requests/FormRequest 继承

示例

<?php

namespace App\Http\Requests;

use Urameshibr\Requests\FormRequest;

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

	public function rules()
	{
		return [
			'mac_address' => 'required|unique:devices,mac_address'
		];
	}
}
  • Laravel Form Request 文档链接

https://laravel.net.cn/docs/5.4/validation#available-validation-rules

祝您使用愉快!