diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 12fcb81d..3125deaf 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->getFirstMediaUrl('companies'); return view('companies.show', compact('company', 'photo')); } diff --git a/app/Http/Controllers/HouseController.php b/app/Http/Controllers/HouseController.php index c330f8aa..8d1a2066 100644 --- a/app/Http/Controllers/HouseController.php +++ b/app/Http/Controllers/HouseController.php @@ -26,6 +26,10 @@ public function update(Request $request, House $house) // TASK: Delete the old file from the storage + if ($house->photo) { + Storage::delete($house->photo); + } + $house->update([ 'name' => $request->name, 'photo' => $filename, @@ -38,5 +42,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); } } diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index fae443fa..f8514d28 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('public/offices', $filename); Office::create([ 'name' => $request->name, diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 95aed4f8..64098fef 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -11,11 +11,12 @@ public function store(Request $request) { $request->validate([ // TASK: Write the validation rule so "logo" file would be MAX 1 megabyte + 'logo' => 'file|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([ diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index b2c485a3..8a8fc00f 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -4,13 +4,22 @@ use Illuminate\Http\Request; use Intervention\Image\Facades\Image; +use Illuminate\Support\Facades\Storage; + class ShopController extends Controller { public function store(Request $request) { $filename = $request->file('photo')->getClientOriginalName(); - $request->file('photo')->storeAs('shops', $filename); + $path = $request->file('photo')->storeAs('shops', $filename); + + // resizing the image + $image = Image::make(Storage::path($path))->resize(500, 500); + + // save the resized image as "resized-$filename" + $resizedFilename = 'resized-' . $filename; + $image->save(Storage::path('shops/' . $resizedFilename)); // TASK: resize the uploaded image from /storage/app/shops/$filename // to size of 500x500 and store it as /storage/app/shops/resized-$filename