Completed all tasks

This commit is contained in:
Thuan Bui
2025-05-11 09:47:13 +09:00
parent 5b954e6ab6
commit f97944f52e
7 changed files with 11402 additions and 1290 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ class CompanyController extends Controller
public function show(Company $company) public function show(Company $company)
{ {
// TASK: retrieve the full URL to the uploaded photo file, using Spatie Media Library // 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')); return view('companies.show', compact('company', 'photo'));
} }
+2
View File
@@ -25,6 +25,7 @@ class HouseController extends Controller
$filename = $request->file('photo')->store('houses'); $filename = $request->file('photo')->store('houses');
// TASK: Delete the old file from the storage // TASK: Delete the old file from the storage
Storage::delete('houses', $house->photo);
$house->update([ $house->update([
'name' => $request->name, 'name' => $request->name,
@@ -38,5 +39,6 @@ class HouseController extends Controller
{ {
// TASK: Return the $house->photo file from "storage/app/houses" folder // TASK: Return the $house->photo file from "storage/app/houses" folder
// for download in browser // for download in browser
return Storage::download($house->photo);
} }
} }
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Office; use App\Models\Office;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class OfficeController extends Controller class OfficeController extends Controller
{ {
@@ -13,6 +14,7 @@ class OfficeController extends Controller
// TASK: Upload the file "photo" so it would be written as // TASK: Upload the file "photo" so it would be written as
// storage/app/public/offices/[original_filename] // storage/app/public/offices/[original_filename]
$request->file('photo')->storeAs('offices', $filename, 'public');
Office::create([ Office::create([
'name' => $request->name, 'name' => $request->name,
+2 -1
View File
@@ -11,11 +11,12 @@ class ProjectController extends Controller
{ {
$request->validate([ $request->validate([
// TASK: Write the validation rule so "logo" file would be MAX 1 megabyte // TASK: Write the validation rule so "logo" file would be MAX 1 megabyte
'logo' => 'max:1024',
]); ]);
// TASK: change the below line so that $filename would contain only filename // TASK: change the below line so that $filename would contain only filename
// The same filename as the original uploaded file // The same filename as the original uploaded file
$filename = '???'; $filename = $request->file('logo')->getClientOriginalName();
$request->file('logo')->storeAs('logos', $filename); $request->file('logo')->storeAs('logos', $filename);
Project::create([ Project::create([
+3
View File
@@ -15,6 +15,9 @@ class ShopController extends Controller
// TASK: resize the uploaded image from /storage/app/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 // to size of 500x500 and store it as /storage/app/shops/resized-$filename
// Use intervention/image package, it's already pre-installed for you // Use intervention/image package, it's already pre-installed for you
$image = Image::make(storage_path('app/shops/' . $filename));
$image->resize(500, 500);
$image->save(storage_path('app/shops/resized-' . $filename));
return 'Success'; return 'Success';
} }
Generated
+1542 -1288
View File
File diff suppressed because it is too large Load Diff
+9850
View File
File diff suppressed because it is too large Load Diff