mirror of
https://github.com/10h30/Test-Laravel-File-Upload.git
synced 2026-07-11 10:46:15 +09:00
Completed all tasks
This commit is contained in:
@@ -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'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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([
|
||||||
|
|||||||
@@ -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
+1541
-1287
File diff suppressed because it is too large
Load Diff
Generated
+9850
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user