From 3d04b615e7b9cd4a671766367de6a97604f07f21 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:06:47 +0800 Subject: [PATCH 1/8] 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 f18d3f199aaa62d5a9b6388b501ae4a6f01e29f5 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:10:44 +0800 Subject: [PATCH 2/8] Update HouseController.php --- app/Http/Controllers/HouseController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/HouseController.php b/app/Http/Controllers/HouseController.php index c330f8aa..ba87351b 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, @@ -38,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 dcbe12b6462b7e3c1dab41a5e22bb1f6f5c2552d Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:11:49 +0800 Subject: [PATCH 3/8] Update OfficeController.php --- app/Http/Controllers/OfficeController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index fae443fa..45b810d2 100644 --- a/app/Http/Controllers/OfficeController.php +++ b/app/Http/Controllers/OfficeController.php @@ -13,6 +13,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('photo')->storeAs('offices',$filename,'public'); Office::create([ 'name' => $request->name, From 1f9949853f36be5359038cfc9274a2983bee9c99 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:19:56 +0800 Subject: [PATCH 4/8] 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..3388e9db 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/app/shops/'.$filename)->resize(500,500)->save('/storage/app/shops/resized-'.$filename); return 'Success'; } From 5c061eff1c575bdc89b66ce8e1eff4a0290599a1 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:21:16 +0800 Subject: [PATCH 5/8] 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 3388e9db..1570311a 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/app/shops/'.$filename)->resize(500,500)->save('/storage/app/shops/resized-'.$filename); + Image::make(storage_path('/app/shops/').$filename)->resize(500,500)->save(storage_path('/app/shops/resized-').$filename); return 'Success'; } From a6a5b60bd66d01f859bc5cd96216ab9182ae8d6b Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:22:35 +0800 Subject: [PATCH 6/8] Update ShopController.php --- app/Http/Controllers/ShopController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 1570311a..b168711d 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,7 +15,8 @@ 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); + // Image::make('storage/app/shops/'.$filename)->resize(500,500)->save('storage/app/shops/resized-'.$filename); return 'Success'; } From a37ba5c9dfb8e657e633b61d720128df8e530299 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:23:21 +0800 Subject: [PATCH 7/8] 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 b168711d..9bbdeea1 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -16,7 +16,7 @@ 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); - // Image::make('storage/app/shops/'.$filename)->resize(500,500)->save('storage/app/shops/resized-'.$filename); + Image::make('storage/app/shops/'.$filename)->resize(500,500)->save('storage/app/shops/resized-'.$filename); return 'Success'; } From 4b8310070c41bbd2064228663904e0506b84786d Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:25:39 +0800 Subject: [PATCH 8/8] 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')); }