From d1d4f6d8bf67a09209c990245b7d49392a17e9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa?= Date: Fri, 24 May 2024 15:18:43 -0500 Subject: [PATCH] All test passed --- app/Http/Controllers/CompanyController.php | 2 +- app/Http/Controllers/HouseController.php | 2 ++ app/Http/Controllers/OfficeController.php | 1 + app/Http/Controllers/ProjectController.php | 8 +++++++- app/Http/Controllers/ShopController.php | 3 +++ composer.json | 2 +- composer.lock | 21 +++++++++++---------- 7 files changed, 26 insertions(+), 13 deletions(-) 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')); } 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); } } diff --git a/app/Http/Controllers/OfficeController.php b/app/Http/Controllers/OfficeController.php index fae443fa..6758ac75 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, diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 95aed4f8..d115b195 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,16 @@ public function store(Request $request) { $request->validate([ // TASK: Write the validation rule so "logo" file would be MAX 1 megabyte + 'logo' => [ + 'file', + 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([ diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index b2c485a3..20d44ef6 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -15,6 +15,9 @@ 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 + $img = Image::make(storage_path('/app/shops/'.$filename)); + $img->resize(500, 500); + $img->save(storage_path('/app/shops/resized-' . $filename)); return 'Success'; } diff --git a/composer.json b/composer.json index ac7b01b7..44026f41 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "laravel/framework": "^10.0", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", - "spatie/laravel-medialibrary": "^10.0.0" + "spatie/laravel-medialibrary": "^10.10" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 3ffebe98..8ed128c8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5986f4b511cd9b94b42fa514e7f64489", + "content-hash": "5438e74699595d27b9089ca1457669bc", "packages": [ { "name": "brick/math", @@ -3358,16 +3358,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "10.7.11", + "version": "10.10.2", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "a6d562d2226c2b339db8299a3a02bacd031edabf" + "reference": "8a00a55ebbf6afc8c1f01c09bb3ee91f67a7f567" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/a6d562d2226c2b339db8299a3a02bacd031edabf", - "reference": "a6d562d2226c2b339db8299a3a02bacd031edabf", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/8a00a55ebbf6afc8c1f01c09bb3ee91f67a7f567", + "reference": "8a00a55ebbf6afc8c1f01c09bb3ee91f67a7f567", "shasum": "" }, "require": { @@ -3375,12 +3375,13 @@ "ext-fileinfo": "*", "ext-json": "*", "illuminate/bus": "^9.18|^10.0", + "illuminate/conditionable": "^9.18|^10.0", "illuminate/console": "^9.18|^10.0", "illuminate/database": "^9.18|^10.0", "illuminate/pipeline": "^9.18|^10.0", "illuminate/support": "^9.18|^10.0", "intervention/image": "^2.7", - "maennchen/zipstream-php": "^2.0", + "maennchen/zipstream-php": "^2.0|^3.0", "php": "^8.0", "spatie/image": "^2.2.2", "spatie/temporary-directory": "^2.0", @@ -3409,7 +3410,7 @@ "suggest": { "league/flysystem-aws-s3-v3": "Required to use AWS S3 file storage", "php-ffmpeg/php-ffmpeg": "Required for generating video thumbnails", - "spatie/pdf-to-image": "Required for generating thumbsnails of PDFs and SVGs" + "spatie/pdf-to-image": "Required for generating thumbnails of PDFs and SVGs" }, "type": "library", "extra": { @@ -3450,7 +3451,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-medialibrary/issues", - "source": "https://github.com/spatie/laravel-medialibrary/tree/10.7.11" + "source": "https://github.com/spatie/laravel-medialibrary/tree/10.10.2" }, "funding": [ { @@ -3462,7 +3463,7 @@ "type": "github" } ], - "time": "2023-02-17T08:44:20+00:00" + "time": "2023-07-24T13:27:13+00:00" }, { "name": "spatie/temporary-directory", @@ -8396,5 +8397,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" }