ljsystem / laravel-prohibited
为您的 Laravel 应用程序添加禁止表单请求验证。
1.1.0
2020-05-22 17:57 UTC
Requires
- php: ^7.2
- illuminate/support: ^6.15|^7.0
- illuminate/translation: ^6.15|^7.0
- illuminate/validation: ^6.15|^7.0
Requires (Dev)
- orchestra/testbench: ^4.0
This package is not auto-updated.
Last update: 2024-09-21 15:35:15 UTC
README
此包为您的 Laravel 应用程序添加了七个新的表单请求验证,允许您以通常要求字段的方式禁止字段。
安装
您可以使用以下命令通过 composer 安装此包
composer require ljsystem/laravel-prohibited
该包将自动注册自己。
用法
安装包后,您可以使用新规则,就像您使用Laravel 官方验证规则一样。
$request->validate([ 'vehicle' => 'required|string|in:car,van,truck,bus,motorcycle', 'speeding' => 'prohibited', 'convertible' => 'prohibited_if:vehicle,motorcycle|integer', 'helmet' => 'prohibited_unless:vehicle,motorcycle|bool', 'hat' => 'prohibited_with:helmet,convertible|bool', 'sunglasses' => 'prohibited_with_all:helmet,helmet_has_visor|bool', 'helmet_has_visor' => 'prohibited_without:helmet|bool', 'helmet_visor_color' => 'prohibited_without_all:helmet,helmet_has_visor|string|in:clear,tinted', ]);
可用验证规则
- Prohibited
- Prohibited If
- Prohibited Unless
- Prohibited With
- Prohibited With All
- Prohibited Without
- Prohibited Without All
prohibited
正在验证的字段必须 不在 输入数据中,无论其值如何。
prohibited_if:anotherfield,value...
正在验证的字段必须在 anotherfield 字段等于任何 value 的情况下不存在。
prohibited_unless:anotherfield,value,...
正在验证的字段必须在 anotherfield 字段等于任何 value 的情况下不存在。
prohibited_with:foo,bar,...
正在验证的字段必须在其他指定字段中至少有一个存在的情况下不存在。
prohibited_with_all:foo,bar,...
正在验证的字段必须在所有其他指定字段都存在的情况下不存在。
prohibited_without:foo,bar,...
正在验证的字段必须在其他指定字段中至少有一个不存在的情况下不存在。
prohibited_without_all:foo,bar,...
正在验证的字段必须在所有其他指定字段都不存在的情况下不存在。
本地化
该包默认包含英语和瑞典语翻译。如果您想添加您自己语言的翻译,可以通过运行以下命令将翻译发布到应用程序的资源目录中
php artisan vendor:publish --provider="Ljsystem\Prohibited\ProhibitedServiceProvider"
这将产生以下文件结构
.
└── resources
└── lang
└── vendor
└── prohibited
├── en
│ └── validation.php
└── sv
└── validation.php
现在您可以复制英文或瑞典文的 validation.php
并将其翻译成您喜欢的语言。如果您想将翻译包含在包中,请随意创建一个 Pull Request。
测试
您可以使用以下命令运行测试
vendor/bin/phpunit
贡献
有关详细信息,请参阅CONTRIBUTING。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。