From 23dd343f236cfa90732afce8766b5b122fb5072b Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 00:59:05 +0800 Subject: [PATCH 1/9] Update PostController.php --- app/Http/Controllers/PostController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..38e02f1f 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,title'] + ] ); // Saving the post From 7ebf2978fa60a17da4505e263da4862d0ffd8266 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:01:50 +0800 Subject: [PATCH 2/9] 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..0347c405 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -13,6 +13,8 @@ public function update(Request $request) // <input name="profile[name]" ... /> // <input name="profile[email]" ... /> // Write validation rules, so both name and email are required + 'profile.name'=>['required'], + 'profile.email'=>['required'] ]); auth()->user()->update($request->profile ?? []); From 94014724240e00cd19e6405897ac174dfe79ae81 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:06:13 +0800 Subject: [PATCH 3/9] Update create.blade.php --- resources/views/projects/create.blade.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..59eb13f6 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -3,7 +3,17 @@ {{-- 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()) +<div class="alert alert-danger"> + <ul> + @foreach($errors->all() as $error) + <li> + {{$error}} + </li> + @endforeach + </ul> +</div> +@endif <form method="POST" action="{{ route('projects.store') }}"> @csrf Title: From deb7cb644470464bcc9e144967233fa737bfeb91 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:07:46 +0800 Subject: [PATCH 4/9] Update create.blade.php --- resources/views/products/create.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/products/create.blade.php b/resources/views/products/create.blade.php index 611b7ef6..35aa56e6 100644 --- a/resources/views/products/create.blade.php +++ b/resources/views/products/create.blade.php @@ -9,6 +9,11 @@ {{-- @directive --}} {{-- {{ $message }} --}} {{-- @endDirective --}} + @error('name') + <div class="alert alert-danger"> + {{$message}} + </div> + @enderror <br /><br /> <button type="submit">Save</button> </form> From 2f4a1788a3181dde2c5bf8bc4758996abe042e49 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:08:29 +0800 Subject: [PATCH 5/9] 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..b2d97fa4 100644 --- a/resources/views/teams/create.blade.php +++ b/resources/views/teams/create.blade.php @@ -3,7 +3,7 @@ Name: <br /> {{-- TASK: change this field so it would contain old value after validation error --}} - <input type="text" name="name" /> + <input type="text" name="name" value="{{old('name')}}" /> <br /><br /> <button type="submit">Save</button> </form> From 2a9e9d7b28d2159a8e8530ee285245b835ccc13f Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:19:19 +0800 Subject: [PATCH 6/9] Create StoreItemRequest.php --- app/Http/Requests/StoreItemRequest.php | 34 ++++++++++++++++++++++++++ 1 file changed, 34 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..3f0ae35c --- /dev/null +++ b/app/Http/Requests/StoreItemRequest.php @@ -0,0 +1,34 @@ +<?php + +namespace App\Http\Requests; + +use Illuminate\Foundation\Http\FormRequest; + +// TASK: Customize the validation error message to say "Please enter the name" +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 782e9230dda1e52da5a143d2083012227772ee45 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:19:58 +0800 Subject: [PATCH 7/9] 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..4047d361 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 2632b95b34aec573753b025e696e22480d1b1fca Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:21:36 +0800 Subject: [PATCH 8/9] 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..2804d89d 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 b5c198f99a63d9246394590a195b4a3dc2400360 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:23:03 +0800 Subject: [PATCH 9/9] Create Uppercase.php --- app/Rules/Uppercase.php | 19 +++++++++++++++++++ 1 file changed, 19 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..021e60f6 --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,19 @@ +<?php + +namespace App\Rules; + +use Closure; +use Illuminate\Contracts\Validation\ValidationRule; + +class Uppercase implements ValidationRule +{ + /** + * Run the validation rule. + */ + public function validate(string $attribute, mixed $value, Closure $fail): void + { + if (strtoupper($value[0]) !== $value[0]) { + $fail('The :attribute does not start with an uppercased letter'); + } + } +}