mirror of
https://github.com/10h30/Test-Laravel-File-Upload.git
synced 2026-06-05 15:07:47 +09:00
Task 4 - download file
This commit is contained in:
@@ -48,3 +48,11 @@ In `app/Http/Controllers/HouseController.php` file, in the `update()` method, we
|
||||
Test method `test_update_file_remove_old_one()`.
|
||||
|
||||
---
|
||||
|
||||
## Task 4. Download the Uploaded File
|
||||
|
||||
In `app/Http/Controllers/HouseController.php` file, in the `download()` method, return the response that would automatically download the file with `$house->photo` filename from `storage/app/houses` folder.
|
||||
|
||||
Test method `test_download_uploaded_file()`.
|
||||
|
||||
---
|
||||
|
||||
@@ -33,4 +33,10 @@ class HouseController extends Controller
|
||||
|
||||
return 'Success';
|
||||
}
|
||||
|
||||
public function download(House $house)
|
||||
{
|
||||
// TASK: Return the $house->photo file from "storage/app/houses" folder
|
||||
// for download in browser
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,6 @@ Route::get('/', function () {
|
||||
});
|
||||
|
||||
Route::post('projects', [\App\Http\Controllers\ProjectController::class, 'store']);
|
||||
|
||||
Route::get('houses/download/{house}', [\App\Http\Controllers\HouseController::class, 'download']);
|
||||
Route::resource('houses', \App\Http\Controllers\HouseController::class);
|
||||
|
||||
@@ -54,11 +54,24 @@ class FileUploadTest extends TestCase
|
||||
$house = House::first();
|
||||
$this->assertTrue(Storage::exists($house->photo));
|
||||
|
||||
$response = $this->put('houses/1', [
|
||||
$response = $this->put('houses/' . $house->id, [
|
||||
'name' => 'Some name',
|
||||
'photo' => UploadedFile::fake()->image('photo2.jpg')
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
$this->assertFalse(Storage::exists($house->photo));
|
||||
}
|
||||
|
||||
public function test_download_uploaded_file()
|
||||
{
|
||||
$this->post('houses', [
|
||||
'name' => 'Some name',
|
||||
'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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user