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/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 ?? []);
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..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',
+ ];
+ }
}
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"
+ ];
+ }
+}
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 @@
+ '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 @@
-
-
+
+
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
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
+
\ No newline at end of file
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 --}}
-
+