如何将Laravel自定义验证规则优先于默认值

问题描述 投票:0回答:1

我有一个自定义验证规则

'title' => ['required', 'min:3', 'unique:transport_locations,title,NULL,id,deleted_at,NULL', new TransportLocationIsInactive],

我想在进行唯一检查之前运行我的自定义规则

'unique:transport_locations,title,NULL,id,deleted_at,NULL'

问题是,它总是首先运行唯一检查,并返回“位置名称已被使用。” :-(

laravel laravel-5.7
1个回答
1
投票

只需更改顺序

'title' => [
    'required', // 1
    'min:3',    // 2
    new TransportLocationIsInactive, // 3
    'unique:transport_locations,title,NULL,id,deleted_at,NULL', // 4
],
© www.soinside.com 2019 - 2024. All rights reserved.