Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve it #219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ 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 = '???';
// Retrieve all media items in the 'photos' collection
$photo = $company->getMedia('companies')[0]->getFullUrl();

return view('companies.show', compact('company', 'photo'));
}

}
5 changes: 5 additions & 0 deletions app/Http/Controllers/HouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public function store(Request $request)

public function update(Request $request, House $house)
{
$oldFilename = $house->photo;
$filename = $request->file('photo')->store('houses');

// TASK: Delete the old file from the storage
if ($oldFilename) {
Storage::delete($oldFilename);
}

$house->update([
'name' => $request->name,
Expand All @@ -36,6 +40,7 @@ public function update(Request $request, House $house)

public function download(House $house)
{
return Storage::download($house->photo);
// TASK: Return the $house->photo file from "storage/app/houses" folder
// for download in browser
}
Expand Down
10 changes: 8 additions & 2 deletions app/Http/Controllers/OfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ class OfficeController extends Controller
{
public function store(Request $request)
{
$filename = $request->file('photo')->getClientOriginalName();
$request->validate([
'name' => 'required|string|max:255',
'photo' => 'required|file|mimes:jpeg,png,jpg,gif|max:2048', // Adjust validation as needed
]);

$file = $request->file('photo');
$filename = $file->getClientOriginalName();
$request->file('photo')->storeAs('offices',$filename,'public');

// TASK: Upload the file "photo" so it would be written as
// storage/app/public/offices/[original_filename]
Expand All @@ -26,5 +33,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' => 'required|file|mimes:jpg,jpeg,png|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
24 changes: 20 additions & 4 deletions app/Http/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ class ShopController extends Controller
{
public function store(Request $request)
{
// Validate the request to ensure a photo is provided
$request->validate([
'photo' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
]);

// Get the original filename
$filename = $request->file('photo')->getClientOriginalName();
$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
// Store the original photo
$path = $request->file('photo')->storeAs('shops', $filename);

// Load the uploaded image
$image = Image::make(storage_path('app/shops/' . $filename));

// Resize the image to 500x500
$image->resize(500, 500);

// Define the new filename for the resized image
$resizedFilename = 'resized-' . $filename;

// Save the resized image
$image->save(storage_path('app/shops/' . $resizedFilename));

return 'Success';
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.15"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
Loading
Loading