From 9fe3d57ae87861f6a01e560705f8e00c01c149c8 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:19:15 +0600 Subject: [PATCH 01/14] T1 Update PostController.php --- app/Http/Controllers/PostController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..42a730cd 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 From 9e6b12eb28ec2710fdcdd4b454a7f1943d153e2e Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:22:52 +0600 Subject: [PATCH 02/14] T1 Update PostController.php --- app/Http/Controllers/PostController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index 42a730cd..dd1e802f 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -9,11 +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]); From e68f57ae3cc3e61c7ea412fa59d4cb606d8e2dbc Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:32:18 +0600 Subject: [PATCH 03/14] T2 Update ProfileController.php --- app/Http/Controllers/ProfileController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index bb6bab39..1d13b110 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|email', ]); auth()->user()->update($request->profile ?? []); From ba1293b1bb039763106af7fb2c25237bd73ac11e Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:47:34 +0600 Subject: [PATCH 04/14] T3 Update create.blade.php --- resources/views/projects/create.blade.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..555e8d7a 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -3,7 +3,15 @@ {{-- TASK: add the validation errors here - with whatever HTML structure you want --}} {{-- in case of title/description empty, visitor should see --}} {{-- "The name field is required." and "The description field is required." --}} - +@if($errors->any()) +
+ +
+@endif
@csrf Title: From 67c08f7cf72c85a7363137622d6d18a91839e38a Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:22:23 +0600 Subject: [PATCH 05/14] T4 Update create.blade.php --- resources/views/products/create.blade.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/views/products/create.blade.php b/resources/views/products/create.blade.php index 611b7ef6..cfcca008 100644 --- a/resources/views/products/create.blade.php +++ b/resources/views/products/create.blade.php @@ -6,9 +6,11 @@
{{-- TASK: show the validation error for the specific "name" field --}} {{-- using one Blade directive: pseudo-code below --}} - {{-- @directive --}} - {{-- {{ $message }} --}} - {{-- @endDirective --}} + @error('name') +
+ {{$message}} +
+ @enderror

From 2cebf6945b08bce601ad328c73ed9c5d08814bbd Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:24:26 +0600 Subject: [PATCH 06/14] T5 Update create.blade.php --- resources/views/teams/create.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/teams/create.blade.php b/resources/views/teams/create.blade.php index 2d003c05..f1afdef2 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 --}} - +

From 2681afe0e0999a9741d28d892499d55f8e96b47d Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:30:05 +0600 Subject: [PATCH 07/14] T6 Create StoreItemRequest.php --- app/Http/Requests/StoreItemRequest.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/Http/Requests/StoreItemRequest.php diff --git a/app/Http/Requests/StoreItemRequest.php b/app/Http/Requests/StoreItemRequest.php new file mode 100644 index 00000000..84cc95e9 --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,29 @@ +namespace App\Http\Requests; + +use Illuminate\Foundation\Http\FormRequest; + +class StoreItemRequest extends FormRequest +{ + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'name' => 'required', + 'description' => 'required', + ]; + } +} From 0bb7f69f93b7c4a5024a3c02945c91f2e9f1ac67 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:43:24 +0600 Subject: [PATCH 08/14] T7 Update UserController.php --- app/Http/Controllers/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 404d7471..94cc6095 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'; } From d519e4d67098357e53c0916a3ea5a21f4936ca0f Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:46:07 +0600 Subject: [PATCH 09/14] T8 Update StoreBuildingRequest.php --- app/Http/Requests/StoreBuildingRequest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..50aae1ae 100644 --- a/app/Http/Requests/StoreBuildingRequest.php +++ b/app/Http/Requests/StoreBuildingRequest.php @@ -30,4 +30,10 @@ public function rules() 'name' => 'required' ]; } + public function messages() + { + return [ + 'name.required' => 'Please enter the name', + ]; + } } From 86772a164f2421262602adf17b33c74aec7d43c7 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:00:28 +0600 Subject: [PATCH 10/14] Update StoreItemRequest.php --- app/Http/Requests/StoreItemRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/StoreItemRequest.php b/app/Http/Requests/StoreItemRequest.php index 84cc95e9..dae08d37 100644 --- a/app/Http/Requests/StoreItemRequest.php +++ b/app/Http/Requests/StoreItemRequest.php @@ -19,11 +19,11 @@ public function authorize() * * @return array */ - public function rules() + public function rules(): array { return [ - 'name' => 'required', - 'description' => 'required', + 'name' => ['required'], + 'description' => ['required'] ]; } } From 86a3a79b75d202bee6343d7b93af0288f8d69232 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:10:07 +0600 Subject: [PATCH 11/14] Update StoreItemRequest.php --- app/Http/Requests/StoreItemRequest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/StoreItemRequest.php b/app/Http/Requests/StoreItemRequest.php index dae08d37..6c6f7a4c 100644 --- a/app/Http/Requests/StoreItemRequest.php +++ b/app/Http/Requests/StoreItemRequest.php @@ -1,3 +1,5 @@ + */ public function rules(): array { From ae9ce02912cbbc93cab3a7e7bf19e8850a2f6e45 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:14:32 +0600 Subject: [PATCH 12/14] T6 Update StoreItemRequest.php --- app/Http/Requests/StoreItemRequest.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/StoreItemRequest.php b/app/Http/Requests/StoreItemRequest.php index 6c6f7a4c..3d773ee8 100644 --- a/app/Http/Requests/StoreItemRequest.php +++ b/app/Http/Requests/StoreItemRequest.php @@ -8,8 +8,10 @@ class StoreItemRequest extends FormRequest { /** * Determine if the user is authorized to make this request. + * + * @return bool */ - public function authorize(): bool + public function authorize() { return true; } @@ -17,13 +19,13 @@ public function authorize(): bool /** * Get the validation rules that apply to the request. * - * @return array + * @return array */ - public function rules(): array + public function rules() { return [ - 'name' => ['required'], - 'description' => ['required'] + 'name' => 'required', + 'description' => 'required', ]; } } From 833f9ae12b7b7b6f6ecd257f974d53d0b493cc8e Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:25:55 +0600 Subject: [PATCH 13/14] T9 Create Uppercase.php --- app/Rules/Uppercase.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/Rules/Uppercase.php diff --git a/app/Rules/Uppercase.php b/app/Rules/Uppercase.php new file mode 100644 index 00000000..2f66c8e2 --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,21 @@ + Date: Sun, 7 Jul 2024 16:30:58 +0600 Subject: [PATCH 14/14] T9 Update Uppercase.php --- app/Rules/Uppercase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Rules/Uppercase.php b/app/Rules/Uppercase.php index 2f66c8e2..b29a92bd 100644 --- a/app/Rules/Uppercase.php +++ b/app/Rules/Uppercase.php @@ -12,10 +12,10 @@ class Uppercase implements ValidationRule * * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail */ - public function validate(string $attribute, mixed $value, Closure $fail): void + public function validate(string $attribute, mixed $value, Closure $fail): void { - if (!ctype_upper(mb_substr($value, 0, 1))) { - $fail("The :attribute does not start with an uppercased letter."); + if ($value != str($value)->title()) { + $fail("The :attribute does not start with an uppercased letter"); } } }