From 9500005866f8cbbbf76f343ba1980a13d537ca92 Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 14:26:16 +0800 Subject: [PATCH 1/7] Pass test 1 --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 95aed4f8..a16aa50f 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -15,7 +15,7 @@ public function store(Request $request) // TASK: change the below line so that $filename would contain only filename // The same filename as the original uploaded file - $filename = '???'; + $filename = $request->file('logo')->getClientOriginalName(); $request->file('logo')->storeAs('logos', $filename); Project::create([ @@ -25,4 +25,4 @@ public function store(Request $request) return 'Success'; } -} +} \ No newline at end of file From 4a17c0d0a94797e46058dc0d28b7b1989841b97f Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 14:32:34 +0800 Subject: [PATCH 2/7] Pass test 2 --- app/Http/Controllers/ProjectController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index a16aa50f..eb913587 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -11,6 +11,7 @@ public function store(Request $request) { $request->validate([ // TASK: Write the validation rule so "logo" file would be MAX 1 megabyte + 'logo' => ['max:1024'] ]); // TASK: change the below line so that $filename would contain only filename From 5c00ad168a87f4f602376e73d7bd6abb203be2d9 Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 14:37:21 +0800 Subject: [PATCH 3/7] Pass test 3 --- app/Http/Controllers/HouseController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HouseController.php b/app/Http/Controllers/HouseController.php index c330f8aa..c25cbe9a 100644 --- a/app/Http/Controllers/HouseController.php +++ b/app/Http/Controllers/HouseController.php @@ -25,6 +25,7 @@ public function update(Request $request, House $house) $filename = $request->file('photo')->store('houses'); // TASK: Delete the old file from the storage + Storage::delete($house->photo); $house->update([ 'name' => $request->name, @@ -39,4 +40,4 @@ public function download(House $house) // TASK: Return the $house->photo file from "storage/app/houses" folder // for download in browser } -} +} \ No newline at end of file From 6f542ff32c97869a5c6361fb2ca675deceec63fe Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 15:00:58 +0800 Subject: [PATCH 4/7] Pass test 4 --- app/Http/Controllers/HouseController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/HouseController.php b/app/Http/Controllers/HouseController.php index c25cbe9a..99d96dc2 100644 --- a/app/Http/Controllers/HouseController.php +++ b/app/Http/Controllers/HouseController.php @@ -39,5 +39,6 @@ public function download(House $house) { // TASK: Return the $house->photo file from "storage/app/houses" folder // for download in browser + return Storage::download($house->photo); } } \ No newline at end of file From 12122506a865170fea53075c7efcd93cbec5a55c Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 21:17:20 +0800 Subject: [PATCH 5/7] Pass test 5 --- app/Http/Controllers/OfficeController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index fae443fa..1a054e2e 100644 --- a/app/Http/Controllers/OfficeController.php +++ b/app/Http/Controllers/OfficeController.php @@ -14,6 +14,12 @@ public function store(Request $request) // TASK: Upload the file "photo" so it would be written as // storage/app/public/offices/[original_filename] + $request->file('photo')->storeAs( + 'offices', + $filename, + 'public' + ); + Office::create([ 'name' => $request->name, 'photo' => $filename, @@ -27,4 +33,4 @@ public function show(Office $office) return view('offices.show', compact('office')); } -} +} \ No newline at end of file From 35a1209b940b9a1feb83d77035e0770f1faa3754 Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 21:36:26 +0800 Subject: [PATCH 6/7] Pass test 6 --- app/Http/Controllers/ShopController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index b2c485a3..dd0faab4 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -16,6 +16,10 @@ public function store(Request $request) // to size of 500x500 and store it as /storage/app/shops/resized-$filename // Use intervention/image package, it's already pre-installed for you + Image::make(storage_path("app/shops/$filename")) + ->resize(500, 500) + ->save(storage_path("app/shops/resized-$filename")); + return 'Success'; } -} +} \ No newline at end of file From c2823d13d973657ded69a0d0906c2012460e7647 Mon Sep 17 00:00:00 2001 From: AlwinJun Date: Sat, 3 Aug 2024 21:45:10 +0800 Subject: [PATCH 7/7] Pass test 7 --- app/Http/Controllers/CompanyController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 12fcb81d..175c2b42 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -20,9 +20,9 @@ public function store(Request $request) public function show(Company $company) { // TASK: retrieve the full URL to the uploaded photo file, using Spatie Media Library - $photo = '???'; + $photo = $company->getFirstMediaUrl('companies'); return view('companies.show', compact('company', 'photo')); } -} +} \ No newline at end of file