From 353090453fcb3a7e58c0e148897be73034c2a2be Mon Sep 17 00:00:00 2001 From: Juan Manuel Corigliano Giuliani <126042007+juancorax@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:08:41 -0300 Subject: [PATCH] Complete tasks --- app/Http/Controllers/PostController.php | 5 ++-- app/Http/Controllers/ProfileController.php | 2 ++ app/Http/Controllers/UserController.php | 2 +- app/Http/Requests/StoreBuildingRequest.php | 14 ++++++++++- app/Http/Requests/StoreItemRequest.php | 29 ++++++++++++++++++++++ app/Rules/Uppercase.php | 21 ++++++++++++++++ resources/views/products/create.blade.php | 4 +++ resources/views/projects/create.blade.php | 11 ++++++++ resources/views/teams/create.blade.php | 5 +++- 9 files changed, 88 insertions(+), 5 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..a73c9859 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -9,10 +9,11 @@ class PostController extends Controller { public function store(Request $request) { - $request->validate( + $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 Post::create(['title' => $request->title]); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index bb6bab39..2b088205 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..d16475bd 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->safe()->except('is_admin')); return 'Success'; } diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..ded4ed1d 100644 --- a/app/Http/Requests/StoreBuildingRequest.php +++ b/app/Http/Requests/StoreBuildingRequest.php @@ -27,7 +27,19 @@ public function authorize() public function rules() { return [ - 'name' => 'required' + 'name' => 'required', + ]; + } + + /** + * Get the error messages for the defined validation rules. + * + * @return array + */ + public function messages(): array + { + 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..a9e22a06 --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required', + 'description' => 'required', + ]; + } +} diff --git a/app/Rules/Uppercase.php b/app/Rules/Uppercase.php new file mode 100644 index 00000000..ac5a1999 --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,21 @@ +{{ $message }} + @enderror +

diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..91efe0ea 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -6,13 +6,24 @@
@csrf + Title:
+

+ Description:


+ + @if ($errors->any()) + + @endif
diff --git a/resources/views/teams/create.blade.php b/resources/views/teams/create.blade.php index 2d003c05..31258a04 100644 --- a/resources/views/teams/create.blade.php +++ b/resources/views/teams/create.blade.php @@ -1,9 +1,12 @@
@csrf + Name:
{{-- TASK: change this field so it would contain old value after validation error --}} - + +

+