Task 4 - download file

This commit is contained in:
PovilasKorop
2021-12-06 08:10:53 +02:00
parent c72be05cea
commit eb7cf686ea
4 changed files with 30 additions and 1 deletions
+8
View File
@@ -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()`.
---
+6
View 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
}
}
+2
View File
@@ -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);
+14 -1
View File
@@ -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));
}
}