laravel-admin form表单中,同时验证两个或多个唯一值

2019-12-16 15:43:34 浏览数 (1)

最近在使用laravel-admin,记录一下用laravel-admin时遇到的问题

一、form表单中,同时验证两个或多个唯一值

代码语言:javascript复制
$name = isset(request()->all()['name']) ? request()->all()['name'] : '';

$form->select('aircraft_id', '机场名称')->options('/admin/data-aircraft')
->creationRules(['required', "unique:cars,aircraft_id,NULL,NULL,name,{$name}"]);
代码语言:javascript复制
$form->select('aircraft_id', '机场名称')->options('/admin/data-aircraft')
->creationRules(['required', "unique:cars,aircraft_id,NULL,NULL,name,{$name}"], ['unique' => '数据已存在'])
->updateRules(['required', "unique:cars,aircraft_id,{$id},id,name,{$name}"], ['unique' => '数据已存在']);

0 人点赞