From 106eb9c827a495f9b33f5bb6dfdf2aa62d9457fc Mon Sep 17 00:00:00 2001 From: MogahidGaffar Date: Mon, 9 Sep 2024 15:25:04 +0300 Subject: [PATCH] test passed --- .env.example => .env | 4 +-- .gitignore | 1 - app/Http/Controllers/ArticleController.php | 2 +- app/Http/Controllers/ItemController.php | 2 ++ app/Http/Controllers/PostController.php | 9 ++++--- app/Http/Controllers/ProfileController.php | 4 +++ app/Http/Controllers/UserController.php | 4 ++- app/Http/Requests/StoreBuildingRequest.php | 9 +++++++ app/Http/Requests/StoreItemRequest.php | 29 ++++++++++++++++++++++ app/Rules/Uppercase.php | 21 ++++++++++++++++ resources/views/products/create.blade.php | 3 +++ resources/views/projects/create.blade.php | 10 ++++++++ resources/views/teams/create.blade.php | 3 ++- 13 files changed, 91 insertions(+), 10 deletions(-) rename .env.example => .env (91%) create mode 100644 app/Http/Requests/StoreItemRequest.php create mode 100644 app/Rules/Uppercase.php diff --git a/.env.example b/.env similarity index 91% rename from .env.example rename to .env index 22c520a6..4cb43b6f 100644 --- a/.env.example +++ b/.env @@ -1,6 +1,6 @@ APP_NAME=Laravel APP_ENV=local -APP_KEY= +APP_KEY=base64:ZSyxUZZ6PlYkbxMiE8SrW75kBWNDwsqBFdZln9r0W0o= APP_DEBUG=true APP_URL=http://localhost @@ -11,7 +11,7 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 -DB_DATABASE=project +DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= diff --git a/.gitignore b/.gitignore index ad69c6fe..76c268a5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ /public/storage /storage/*.key /vendor -.env .env.backup .env.production .phpunit.result.cache diff --git a/app/Http/Controllers/ArticleController.php b/app/Http/Controllers/ArticleController.php index a1955393..67cf0fd4 100644 --- a/app/Http/Controllers/ArticleController.php +++ b/app/Http/Controllers/ArticleController.php @@ -18,4 +18,4 @@ public function store(Request $request) Article::create(['title' => $request->title]); } -} +} \ No newline at end of file diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 7c8082ae..6739f0a9 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -18,3 +18,5 @@ public function store(StoreItemRequest $request) } } + + diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index cd0808b7..83958b98 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -9,10 +9,11 @@ class PostController extends Controller { 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 - ); + + + $request->validate([ + 'title' => 'required|unique:posts', + ]); // Saving the post Post::create(['title' => $request->title]); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index bb6bab39..0df473c7 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -13,8 +13,12 @@ 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 ?? []); return 'Success'; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 404d7471..f69b44b5 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -11,7 +11,9 @@ 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()); + $validatedData = $request->validated(); + unset($validatedData['is_admin']); + $user->update($validatedData); return 'Success'; } diff --git a/app/Http/Requests/StoreBuildingRequest.php b/app/Http/Requests/StoreBuildingRequest.php index fbd8c064..b0397bfb 100644 --- a/app/Http/Requests/StoreBuildingRequest.php +++ b/app/Http/Requests/StoreBuildingRequest.php @@ -30,4 +30,13 @@ public function rules() 'name' => 'required' ]; } + + + 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..e8bf0592 --- /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..6836ff68 --- /dev/null +++ b/app/Rules/Uppercase.php @@ -0,0 +1,21 @@ +
+ @error('name') +
{{ $message }}
+@enderror diff --git a/resources/views/projects/create.blade.php b/resources/views/projects/create.blade.php index dc19b63b..da55c74c 100644 --- a/resources/views/projects/create.blade.php +++ b/resources/views/projects/create.blade.php @@ -4,6 +4,16 @@ {{-- 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: diff --git a/resources/views/teams/create.blade.php b/resources/views/teams/create.blade.php index 2d003c05..71579b4c 100644 --- a/resources/views/teams/create.blade.php +++ b/resources/views/teams/create.blade.php @@ -3,7 +3,8 @@ Name:
{{-- TASK: change this field so it would contain old value after validation error --}} - + +