From 38fbce32f68adab5570c4f8502d19bdafacae0e5 Mon Sep 17 00:00:00 2001 From: Fahry Ibrahim Date: Sun, 1 Sep 2024 12:58:17 +0700 Subject: [PATCH] coba --- app/Http/Controllers/PostController.php | 1 + app/Http/Controllers/ProfileController.php | 2 ++ app/Http/Controllers/UserController.php | 2 +- app/Http/Requests/StoreBuildingRequest.php | 7 +++++ app/Http/Requests/StoreItemRequest.php | 34 ++++++++++++++++++++++ app/Rules/Uppercase.php | 22 ++++++++++++++ resources/views/products/create.blade.php | 3 ++ resources/views/projects/create.blade.php | 6 ++-- resources/views/teams/create.blade.php | 2 +- 9 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 app/Http/Requests/StoreItemRequest.php create mode 100644 app/Rules/Uppercase.php diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..ae26a753 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -12,6 +12,7 @@ public function store(Request $request) $request->validate( // ... TASK: write validation here so that "title" field // would be required and unique in the "posts" DB table + 'title' => 'required|unique:posts' ); // Saving the post diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index bb6bab39..8cd35637 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -13,6 +13,8 @@ public function update(Request $request) // // // Write validation rules, so both name and email are required + 'profile.name' => 'required', + 'profile.email' => 'required' ]); auth()->user()->update($request->profile ?? []); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 404d7471..a6d0f989 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -11,7 +11,7 @@ public function update(User $user, UpdateUserRequest $request) { // TASK: change this line to not allow is_admin field to be updated // Update only the fields that are validated in UpdateUserRequest - $user->update($request->all()); + $user->update($request->validated()); return 'Success'; } diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..855e27ef 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' + ] + } } diff --git a/app/Http/Requests/StoreItemRequest.php b/app/Http/Requests/StoreItemRequest.php new file mode 100644 index 00000000..baf920e8 --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,34 @@ + 'required', + 'description' => 'required' + ]; + } +} diff --git a/app/Rules/Uppercase.php b/app/Rules/Uppercase.php new file mode 100644 index 00000000..e2366c6c --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,22 @@ +{{ $message }} + @enderror

diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..cdcb23d9 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -8,11 +8,9 @@ @csrf Title:
- -

+

Description:
- -

+

diff --git a/resources/views/teams/create.blade.php b/resources/views/teams/create.blade.php index 2d003c05..37ae1412 100644 --- a/resources/views/teams/create.blade.php +++ b/resources/views/teams/create.blade.php @@ -3,7 +3,7 @@ Name:
{{-- TASK: change this field so it would contain old value after validation error --}} - +