将Laravel验证与列无关的位置
例如,我有一个HTTP请求来处理某些实体创建(让它成为角色) 验证看起来像这样:
class CreateRole extends FormRequest
{
public function rules()
{
return [
'name' => 'required|string|max:255',
'permissions' => ['required', 'array'],
...
我有一些与名称或权限列无关的限制。 例如,可以创建的最大角色数量。
这种自定义验证可以放置在name
属性上,但看起来错误。
ps:我知道自定义验证器。关于将其放置的问题...
For example, I have an HTTP request that handles some entity creation (let it be Role)
And validation looks like this:
class CreateRole extends FormRequest
{
public function rules()
{
return [
'name' => 'required|string|max:255',
'permissions' => ['required', 'array'],
...
And I have some restrictions that are not related to either name or permission column.
For example the maximum amount of roles that can be created.
Such custom validation can be placed to the name
property, but it looks wrong.
PS: I know about custom validators. Question about where to place it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在“ hook ”中使用
replect request
createrole.php
You can use
after hook
in the form requestCreateRole.php
您必须创建自定义验证类,如此 laravel文档并将其放入下面的效力类中。
You have to create custom validation class as shown in this Laravel document and place into you validatior class like below.