8000 fix 自定义错误验证消息输出 · laraveladmin-cn/laraveladmin@3010091 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3010091

Browse files
author
张世平
committed
fix 自定义错误验证消息输出
1 parent 263be04 commit 3010091

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/Http/Controllers/Traits/ResourceController.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function whereValidate(&$validate_rules, $value, $key)
355355
protected function existFullTextSearch(){
356356
if(!isset($this->hasFullTextSearch) || is_null($this->hasFullTextSearch)){
357357
$this->hasFullTextSearch = collect(Arr::get($this->getOptions(),'where',[]))
358-
->where('exp','=','search')
358+
->where('exp','=','search')
359359
->first()?:false;
360360
}
361361
return $this->hasFullTextSearch;
@@ -512,7 +512,9 @@ public function delete()
512512
public function create(\Illuminate\Http\Request $request)
513513
{
514514
$validate = $this->getValidateRule(0);
515-
$validator = Validator::make($request->all(), $validate);
515+
$messages = $this->validateMessages??[];
516+
$customAttributes = $this->validateCustomAttributes??[];
517+
$validator = Validator::make($request->all(), $validate,$messages,$customAttributes);
516518
if ($validator->fails()) {
517519
return Response::returns([
518520
'errors' => $validator->errors()->toArray(),
@@ -556,7 +558,9 @@ public function update($id = 0)
556558
$request = Request::instance();
557559
$id = $id ?: $request->get('id', 0);
558560
$validate = $this->getValidateRule($id);
559-
$validator = Validator::make($request->all(), $validate);
561+
$messages = $this->validateMessages??[];
562+
$customAttributes = $this->validateCustomAttributes??[];
563+
$validator = Validator::make($request->all(), $validate,$messages,$customAttributes);
560564
if ($validator->fails()) {
561565
return Response::returns([
562566
'errors' => $validator->errors()->toArray(),
@@ -660,7 +664,7 @@ protected function getWithOptionModel($fields_key = 'showIndexFields',$unset_ord
660664
}else{
661665
$obj = $obj->where($item['key'],$item['exp'],$item['val']);
662666
}
663-
});
667+
});
664668
collect(Arr::get($options,'order',[]))
665669
->each(function ($item,$key)use(&$obj){
666670
$obj = $obj->orderBy($key,$item);
@@ -1232,7 +1236,9 @@ public function import()
12321236
})->filter(function ($item) use (&$errors, $key_name, $relation_keys, $maps1, $multipleFields) { //数据验证
12331237
$data = getRelationData($item);
12341238
$data = $this->handleImportValidateBefore($data);
1235-
$validator = Validator::make($data, $this->getImportValidateRule(Arr::get($data, $key_name, 0), $data), [], $this->exportFieldsName);
1239+
$messages = $this->validateMessages??[];
1240+
$customAttributes = $this->validateCustomAttributes??[];
1241+
$validator = Validator::make($data, $this->getImportValidateRule(Arr::get($data, $key_name, 0), $data), $messages, array_merge($customAttributes,$this->exportFieldsName));
12361242
$flog = !$validator->fails(); //验证状态
12371243
if ($validator->fails()) {
12381244
$item['error'] = collect($validator->errors()->toArray())->map(function ($v, $k) {

0 commit comments

Comments
 (0)
0