From e33b370f3f5fbd822be335be1db289f978f861b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20V=C4=83n=20Tuy=E1=BA=BFn?= Date: Tue, 17 Oct 2023 21:43:59 +0700 Subject: [PATCH] Task 8: Customize validation messages DONE --- app/Http/Controllers/BuildingController.php | 2 +- app/Http/Requests/StoreBuildingRequest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/BuildingController.php b/app/Http/Controllers/BuildingController.php index 9c752ab8..875b4cbb 100644 --- a/app/Http/Controllers/BuildingController.php +++ b/app/Http/Controllers/BuildingController.php @@ -17,7 +17,7 @@ public function create() // TASK: Customize the validation error message to say "Please enter the name" public function store(StoreBuildingRequest $request) { - Building::create($validator->validated()); + Building::create($request->validated()); return 'Success'; } diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..a917fbff 100644 --- a/app/Http/Requests/StoreBuildingRequest.php +++ b/app/Http/Requests/StoreBuildingRequest.php @@ -30,4 +30,11 @@ public function rules() 'name' => 'required' ]; } + + public function messages() + { + return [ + 'name.required' => 'Please enter the name' + ]; + } }