From 065bdca421cffd65ca1a888a64c7f8f0d221717f Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Tue, 15 Nov 2022 18:02:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BF=AE=E6=94=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/FriendLinkController.php | 3 +- app/Http/Requestes/FriendLinkRequest.php | 4 +- .../Requestes/FriendLinkUpdateRequest.php | 49 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/Http/Requestes/FriendLinkUpdateRequest.php diff --git a/app/Http/Controllers/FriendLinkController.php b/app/Http/Controllers/FriendLinkController.php index 858e8da..51ee47f 100644 --- a/app/Http/Controllers/FriendLinkController.php +++ b/app/Http/Controllers/FriendLinkController.php @@ -7,6 +7,7 @@ use App\Http\Resources\FriendLinkResource; use App\Models\FriendLink; use Illuminate\Http\Request; use App\Http\Requestes\FriendLinkRequest; +use App\Http\Requestes\FriendLinkUpdateRequest; use App\Services\OperationLogService; use App\Enums\OperationType; @@ -35,7 +36,7 @@ class FriendLinkController extends Controller return $this->json(FriendLinkResource::make($friendLink)); } - public function update(FriendLink $friendLink, FriendLinkRequest $request){ + public function update(FriendLink $friendLink, FriendLinkUpdateRequest $request){ $friendLink->update($request->input()); (new OperationLogService())->inLog(OperationType::Update, '', $friendLink, $request->input()); diff --git a/app/Http/Requestes/FriendLinkRequest.php b/app/Http/Requestes/FriendLinkRequest.php index 5961d9b..b7ed0ad 100644 --- a/app/Http/Requestes/FriendLinkRequest.php +++ b/app/Http/Requestes/FriendLinkRequest.php @@ -18,9 +18,9 @@ class FriendLinkRequest extends FormRequest public function rules() { return [ - 'name' => 'required', + 'name' => 'required|string', 'type' => 'required|integer|min:1|max:3', - 'content' => 'required', + 'content' => 'required|string', 'sort' => 'required|integer', 'is_recommend' => 'required|boolean', 'is_show'=> 'required|boolean', diff --git a/app/Http/Requestes/FriendLinkUpdateRequest.php b/app/Http/Requestes/FriendLinkUpdateRequest.php new file mode 100644 index 0000000..9924387 --- /dev/null +++ b/app/Http/Requestes/FriendLinkUpdateRequest.php @@ -0,0 +1,49 @@ + 'filled|string', + 'type' => 'filled|integer|min:1|max:3', + 'content' => 'filled|string', + 'sort' => 'filled|integer', + 'is_recommend' => 'filled|boolean', + 'is_show'=> 'filled|boolean', + ]; + } + + public function messages() + { + $messages = [ + 'name' => '请填写标题', + 'type' => '请选择类型', + 'content' => '请填充内容', + 'sort' => '请填写排序', + 'is_recommend' => '请设置推荐', + 'is_show' => '请设置显示' + ]; + + return $messages; + } + + protected function failedValidation(Validator $validator) + { + $error = $validator->errors()->all(); + throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]])); + } +}