博客验证检查添加校验组件

Signed-off-by: XiaoLFeng <gm@x-lf.cn>
This commit is contained in:
筱锋xiao_lfeng 2023-06-30 10:01:41 +08:00
parent 7bf090d6e6
commit 01a3c71f02

View File

@ -264,6 +264,13 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
{
/** @var array $returnData Json的 return 返回值 */
// 验证数据
$dataCheck = Validator::make($request->all(),[
'id' => 'required|int',
'userEmail' => 'required|email',
'userCode' => 'string|min:6|max:64|regex:#^[0-9A-Za-z]+$#',
]);
if ($dataCheck->fails()) {
$resultBlog = DB::table('blog_link')
->select('id', 'blogOwnEmail')
->find((int)$request->id);
@ -380,6 +387,29 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
],
];
}
} else {
$errorType = array_keys($dataCheck->failed());
$i = 0;
foreach ($dataCheck->failed() as $valueData) {
$errorInfo[$errorType[$i]] = array_keys($valueData);
if ($i == 0) {
$errorSingle = [
'info' => $errorType[$i],
'need' => $errorInfo[$errorType[$i]],
];
}
$i++;
}
$returnData = [
'output' => 'DataFormatError',
'code' => 403,
'data' => [
'message' => '输入内容有错误',
'errorSingle' => $errorSingle,
'error' => $errorInfo,
],
];
}
return Response::json($returnData, $returnData['code']);
}