Skip to content

Commit

Permalink
Complete tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
juancorax committed Dec 27, 2024
1 parent 5b954e6 commit d574341
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ 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'));
}

}
4 changes: 4 additions & 0 deletions app/Http/Controllers/HouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function update(Request $request, House $house)
$filename = $request->file('photo')->store('houses');

// TASK: Delete the old file from the storage
if ($house->photo) {
Storage::delete($house->photo);
}

$house->update([
'name' => $request->name,
Expand All @@ -38,5 +41,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);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/OfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')->storePubliclyAs('offices', $filename);

Office::create([
'name' => $request->name,
Expand All @@ -26,5 +27,4 @@ public function show(Office $office)
{
return view('offices.show', compact('office'));
}

}
3 changes: 2 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Intervention\Image\ImageManager;

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);

// 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 = ImageManager::imagick()->read($path);
$image->resize(500);

$image->storeAs('shops', 'resized-'.$filename);

return 'Success';
}
Expand Down

0 comments on commit d574341

Please sign in to comment.