From e83de3e6007c476f7599e3ed139107c4f0efbd1d Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:09:13 +0545 Subject: [PATCH 1/9] test passed 1 --- .env.example | 6 +++--- app/Http/Controllers/PostController.php | 3 +++ config/database.php | 10 +++++----- phpunit.xml | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 22c520a6..4dc68dde 100644 --- a/.env.example +++ b/.env.example @@ -10,10 +10,10 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=project +DB_PORT=10111 +DB_DATABASE=validation_test DB_USERNAME=root -DB_PASSWORD= +DB_PASSWORD=root BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..db074d0c 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -12,6 +12,9 @@ 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/config/database.php b/config/database.php index b42d9b30..3c951aa0 100644 --- a/config/database.php +++ b/config/database.php @@ -47,10 +47,10 @@ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '3306'), - 'database' => env('DB_DATABASE', 'forge'), - 'username' => env('DB_USERNAME', 'forge'), - 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', '10111'), + 'database' => env('DB_DATABASE', 'validation_test'), + 'username' => env('DB_USERNAME', 'root'), + 'password' => env('DB_PASSWORD', 'root'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', @@ -123,7 +123,7 @@ 'options' => [ 'cluster' => env('REDIS_CLUSTER', 'redis'), - 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), + 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'), ], 'default' => [ diff --git a/phpunit.xml b/phpunit.xml index a0b799dd..eca4e57b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,8 +18,8 @@ - - + + From 5114a6e80cab3bc6eebeed92ee769948e2fc9bf2 Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:14:23 +0545 Subject: [PATCH 2/9] test2 passed --- 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..7adc8306 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 ?? []); From bd63a1b7c1a1840878b51e0d1f446762718aa16d Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:16:33 +0545 Subject: [PATCH 3/9] test3 passed --- resources/views/projects/create.blade.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..b45e182b 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -3,6 +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()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+@endif
@csrf @@ -15,4 +24,4 @@

-
+ \ No newline at end of file From 98da07d4b6a1a49ad6410851767d0f42738ab67f Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:18:00 +0545 Subject: [PATCH 4/9] test4 passed --- resources/views/products/create.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/views/products/create.blade.php b/resources/views/products/create.blade.php index 611b7ef6..4dc7ceb8 100644 --- a/resources/views/products/create.blade.php +++ b/resources/views/products/create.blade.php @@ -9,6 +9,9 @@ {{-- @directive --}} {{-- {{ $message }} --}} {{-- @endDirective --}} + @error('name') +
{{ $message }}
+ @enderror

- + \ No newline at end of file From c30ac200dd2798cba39ac2bb9c244a08f1cec4ba Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:19:09 +0545 Subject: [PATCH 5/9] test5 passed --- resources/views/teams/create.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/teams/create.blade.php b/resources/views/teams/create.blade.php index 2d003c05..e8d71ee1 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 --}} - +

- + \ No newline at end of file From 3acb563d274c44522409c2dbb17d3efafed22cb7 Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:21:21 +0545 Subject: [PATCH 6/9] test6 passed --- 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..7f0cfa45 --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,29 @@ + + */ + public function rules(): array + { + return [ + "name" => "required", + "description" => "required" + ]; + } +} From 2fcd0931f0129eb5f449e14c14c4f439a9b78524 Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:23:05 +0545 Subject: [PATCH 7/9] test7 passed --- 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..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'; } From 8d16fef1aeaba7a72776784e157e72b25261f78d Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:25:04 +0545 Subject: [PATCH 8/9] test8 passed --- app/Http/Requests/StoreBuildingRequest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..7fd5d258 100644 --- a/app/Http/Requests/StoreBuildingRequest.php +++ b/app/Http/Requests/StoreBuildingRequest.php @@ -30,4 +30,16 @@ public function rules() 'name' => 'required' ]; } + + /** + * Get the error messages for the defined validation rules. + * + * @return array + */ + public function messages(): array + { + return [ + 'name.required' => 'Please enter the name', + ]; + } } From 5cbca08ca623da5a5b3dff7ee694c5fd065903ec Mon Sep 17 00:00:00 2001 From: Sudeep-K Date: Thu, 25 Jan 2024 15:30:51 +0545 Subject: [PATCH 9/9] =?UTF-8?q?all=20test=20cases=20passed=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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..236c10a6 --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,21 @@ +