From 0e15459b3245170a22c824dc22a344965e2ef81e Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 14:54:03 +0800 Subject: [PATCH 01/12] Update ProjectController.php --- app/Http/Controllers/ProjectController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 95aed4f8..62e79177 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -4,6 +4,7 @@ use App\Models\Project; use Illuminate\Http\Request; +use Illuminate\Validation\Rules\File; class ProjectController extends Controller { @@ -11,11 +12,12 @@ public function store(Request $request) { $request->validate([ // TASK: Write the validation rule so "logo" file would be MAX 1 megabyte + 'logo'=>[File::image()->max(1024)] ]); // 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([ From c388f3e944dbc383d27bda0ccefe2d8a499d30cb Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 14:55:46 +0800 Subject: [PATCH 02/12] Update HouseController.php --- 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 c330f8aa..fb030935 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, From e0003289d15ee3dfb4f02de0a6ba33592646915f Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 14:56:59 +0800 Subject: [PATCH 03/12] Update HouseController.php --- 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 fb030935..ba87351b 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); } } From 91d88db78375dca36e534fa0f5fd6266917cf397 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 14:57:58 +0800 Subject: [PATCH 04/12] Update OfficeController.php --- app/Http/Controllers/OfficeController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index fae443fa..5032ac0f 100644 --- a/app/Http/Controllers/OfficeController.php +++ b/app/Http/Controllers/OfficeController.php @@ -14,6 +14,8 @@ public function store(Request $request) // TASK: Upload the file "photo" so it would be written as // storage/app/public/offices/[original_filename] + $request->file('file')->storeAs('officies',$filename,'public'); + Office::create([ 'name' => $request->name, 'photo' => $filename, From cb880e533214a824d0bdc98eca928918a020266e Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:01:27 +0800 Subject: [PATCH 05/12] Update ShopController.php --- app/Http/Controllers/ShopController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index b2c485a3..c94f7ca9 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,6 +15,7 @@ public function store(Request $request) // TASK: resize the uploaded image from /storage/app/shops/$filename // 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'; } From 05423baaa29751a128f01ce0e87ea273c117b05c Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:03:37 +0800 Subject: [PATCH 06/12] Update CompanyController.php --- app/Http/Controllers/CompanyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 12fcb81d..50d8ebf5 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -20,7 +20,7 @@ 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->getMedia('companies')[0]->getFullUrl(); return view('companies.show', compact('company', 'photo')); } From 499a2e464ba7a44ff5901a395f540cae6747cc7d Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:07:23 +0800 Subject: [PATCH 07/12] Update OfficeController.php --- app/Http/Controllers/OfficeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index 5032ac0f..c6621701 100644 --- a/app/Http/Controllers/OfficeController.php +++ b/app/Http/Controllers/OfficeController.php @@ -14,7 +14,7 @@ public function store(Request $request) // TASK: Upload the file "photo" so it would be written as // storage/app/public/offices/[original_filename] - $request->file('file')->storeAs('officies',$filename,'public'); + $request->file('file')->storeAs('offices',$filename,'public'); Office::create([ 'name' => $request->name, From f6e94a8de44beee6d089e5d01ccc3b89d96cc236 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:08:15 +0800 Subject: [PATCH 08/12] Update ShopController.php --- app/Http/Controllers/ShopController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index c94f7ca9..185baa62 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,7 +15,7 @@ public function store(Request $request) // TASK: resize the uploaded image from /storage/app/shops/$filename // 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)); + Image::make(storage_path('/app/shops/'.$filename)).resize(500,500)->save(storage_path('/app/shops/resized-'.$filename)); return 'Success'; } From c703b07f593f1b14dda57b937ed1adc26afd7c03 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:12:20 +0800 Subject: [PATCH 09/12] Update OfficeController.php --- app/Http/Controllers/OfficeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index c6621701..bca5d4aa 100644 --- a/app/Http/Controllers/OfficeController.php +++ b/app/Http/Controllers/OfficeController.php @@ -14,7 +14,7 @@ public function store(Request $request) // TASK: Upload the file "photo" so it would be written as // storage/app/public/offices/[original_filename] - $request->file('file')->storeAs('offices',$filename,'public'); + $request->file('photo')->storeAs('offices',$filename,'public'); Office::create([ 'name' => $request->name, From c8621402274a0b329b640dbcc978b04a8f286138 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:12:53 +0800 Subject: [PATCH 10/12] Update ShopController.php --- app/Http/Controllers/ShopController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 185baa62..c1cb4f7d 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,7 +15,7 @@ public function store(Request $request) // TASK: resize the uploaded image from /storage/app/shops/$filename // 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)); + Image::make(storage_path('app/shops/').$filename).resize(500,500)->save(storage_path('app/shops/resized-').$filename); return 'Success'; } From 37c3defc9bcad06ed676c27d327dbcc874c6bd9d Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:15:49 +0800 Subject: [PATCH 11/12] Update ShopController.php --- app/Http/Controllers/ShopController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index c1cb4f7d..098aa89d 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,7 +15,7 @@ public function store(Request $request) // TASK: resize the uploaded image from /storage/app/shops/$filename // 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); + Image::make(storage_path('/app/shops/').$filename).resize(500,500)->save(storage_path('/app/shops/resized-').$filename); return 'Success'; } From 772c301d09cdb1dd5790f907217383dc345e2a32 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:16:48 +0800 Subject: [PATCH 12/12] Update ShopController.php --- app/Http/Controllers/ShopController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 098aa89d..32850f16 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,7 +15,7 @@ public function store(Request $request) // TASK: resize the uploaded image from /storage/app/shops/$filename // 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); + Image::make(storage_path('app/shops/'.$filename))->resize(500,500)->save(storage_path('app/shops/resized-'.$filename)); return 'Success'; }