diff --git a/app/Http/Controllers/BuildingController.php b/app/Http/Controllers/BuildingController.php index 9c752ab8..875b4cbb 100644 --- a/app/Http/Controllers/BuildingController.php +++ b/app/Http/Controllers/BuildingController.php @@ -17,7 +17,7 @@ public function create() // TASK: Customize the validation error message to say "Please enter the name" public function store(StoreBuildingRequest $request) { - Building::create($validator->validated()); + Building::create($request->validated()); return 'Success'; } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 7c8082ae..43a8888d 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -16,5 +16,4 @@ public function store(StoreItemRequest $request) return 'Success'; } - } diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..58a42b30 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,title'], ); // Saving the post 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..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..bd98a463 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..deea9b58 --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,30 @@ + + */ + 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..f7c08358 --- /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..adfda363 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -4,6 +4,7 @@ {{-- in case of title/description empty, visitor should see --}} {{-- "The name field is required." and "The description field is required." --}} +
@csrf Title: @@ -16,3 +17,12 @@

+ + 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 --}} - +