Skip to content
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
3 changes: 2 additions & 1 deletion app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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 = '???';
$mediaItems = $company->getMedia("companies");
$photo = $mediaItems[0]->getFullUrl();

return view('companies.show', compact('company', 'photo'));
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/HouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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,
'photo' => $filename,
Expand All @@ -38,5 +38,6 @@ public function download(House $house)
{
// TASK: Return the $house->photo file from "storage/app/houses" folder
// for download in browser
return response()->download('storage/app/'.$house->photo);
}
}
8 changes: 7 additions & 1 deletion app/Http/Controllers/OfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public function store(Request $request)

// TASK: Upload the file "photo" so it would be written as
// storage/app/public/offices/[original_filename]

$filename = $request->file('photo')->getClientOriginalName();
//$v = $request->photo->move(public_path('\offices\\'), $filename);
$destinationPath = 'offices';
//$request->photo->move(public_path($destinationPath), $filename);
//$request->photo->move(public_path('/offices'), $filename);
//request('photo')->store('public/offices');
$request->file('photo')->storeAs('public/offices',$filename);
Office::create([
'name' => $request->name,
'photo' => $filename,
Expand Down
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'=>'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
15 changes: 9 additions & 6 deletions app/Http/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
//use Illuminate\Http\File;
use Intervention\Image\Facades\Image;

use Illuminate\Support\Facades\Storage;
class ShopController extends Controller
{
public function store(Request $request)
{
$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

$path = storage_path('app/shops/' . $filename);
if (!File::exists($path)) {
abort(404);
}
$name ='resized-'.$filename;
$resize = Image::make($path)->resize(500,500)->save('storage/app/shops/'.$name);
return 'Success';
}
}
Binary file added bar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added foo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-ERimij2W.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-EvF3HEya.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-FSMU1V42.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-JND1RMtq.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-LK5o0B0t.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-PBpPpBSb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-S9S6uVNL.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-TJUbTnWV.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-Twl15vDp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-UCKFIIbF.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-W0co1hTd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-WaQR8soE.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-ZqdIUVes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-bJmO2iVs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-jHCLXXFG.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-o56uB4vZ.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-rfH4v9Dx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-smNm37t2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resized-tviqF9xa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 30 additions & 32 deletions tests/Feature/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class FileUploadTest extends TestCase
{
use RefreshDatabase;

public function test_original_filename_upload()
{
$filename = 'logo.jpg';
Expand Down Expand Up @@ -73,7 +72,6 @@ public function test_download_uploaded_file()
'photo' => UploadedFile::fake()->image('photo.jpg')
]);
$house = House::first();

$response = $this->get('houses/download/' . $house->id);
$response->assertStatus(200);
$response->assertDownload(str_replace('houses/', '', $house->photo));
Expand All @@ -91,39 +89,39 @@ public function test_public_file_show()

$this->assertTrue(Storage::disk('public')->exists('offices/' . $filename));


$response = $this->get('offices/' . $office->id);
$response->assertStatus(200);
$response->assertSee(public_path('offices/' . $filename));
}

public function test_upload_resize()
{
$filename = Str::random(8) . '.jpg';

$response = $this->post('shops', [
'name' => 'Some name',
'photo' => UploadedFile::fake()->image($filename, 1000, 1000)
]);
$response->assertStatus(200);

$image = Image::make(storage_path('app/shops/resized-' . $filename));
$this->assertEquals(500, $image->width());
$this->assertEquals(500, $image->height());
}

public function test_spatie_media_library()
{
$filename = Str::random(8) . '.jpg';

$response = $this->post('companies', [
'name' => 'Some name',
'photo' => UploadedFile::fake()->image($filename)
]);
$response->assertStatus(200);

$company = Company::first();
$response = $this->get('companies/' . $company->id);
$response->assertStatus(200);
$response->assertSee('storage/' . $company->id . '/' . $filename);
}
public function test_upload_resize()
{
$filename = Str::random(8) . '.jpg';

$response = $this->post('shops', [
'name' => 'Some name',
'photo' => UploadedFile::fake()->image($filename, 1000, 1000)
]);
$response->assertStatus(200);

$image = Image::make(storage_path('app/shops/resized-' . $filename));
$this->assertEquals(500, $image->width());
$this->assertEquals(500, $image->height());
}
public function test_spatie_media_library()
{
$filename = Str::random(8) . '.jpg';

$response = $this->post('companies', [
'name' => 'Some name',
'photo' => UploadedFile::fake()->image($filename)
]);
$response->assertStatus(200);

$company = Company::first();
$response = $this->get('companies/' . $company->id);
$response->assertStatus(200);
$response->assertSee('storage/' . $company->id . '/' . $filename);
}
}