From 27d4fc009a015a786211d3493e49a90e3231e7aa Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 15 Mar 2019 22:50:42 +0800 Subject: [PATCH 1/2] Update user photo upload filesystem Add FILESYSTEM_DRIVER env on phpunit.xml --- app/Http/Controllers/UsersController.php | 8 +++----- phpunit.xml | 1 + tests/Feature/UsersProfileTest.php | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 276b3a0..5619a86 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -179,13 +179,11 @@ class UsersController extends Controller 'photo' => 'required|image|max:200', ]); - $storage = env('APP_ENV') == 'testing' ? 'avatars' : 'public'; - - if (Storage::disk($storage)->exists($user->photo_path)) { - Storage::disk($storage)->delete($user->photo_path); + if (Storage::exists($user->photo_path)) { + Storage::delete($user->photo_path); } - $user->photo_path = $request->photo->store('images', $storage); + $user->photo_path = $request->photo->store('images'); $user->save(); return back(); diff --git a/phpunit.xml b/phpunit.xml index f5f6354..bec66c3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -29,5 +29,6 @@ + diff --git a/tests/Feature/UsersProfileTest.php b/tests/Feature/UsersProfileTest.php index d92cdb9..2bdbf9b 100644 --- a/tests/Feature/UsersProfileTest.php +++ b/tests/Feature/UsersProfileTest.php @@ -96,7 +96,7 @@ class UsersProfileTest extends TestCase /** @test */ public function user_can_upload_their_own_photo() { - Storage::fake('avatars'); + Storage::fake(config('filesystems.default')); $user = $this->loginAsUser(); $this->visit(route('users.edit', $user->id)); @@ -110,7 +110,7 @@ class UsersProfileTest extends TestCase $user = $user->fresh(); $this->assertNotNull($user->photo_path); - Storage::disk('avatars')->assertExists($user->photo_path); + Storage::assertExists($user->photo_path); } /** @test */ From 3e157b9ff870e9813c18f7337b44ed093934add5 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 15 Mar 2019 22:58:34 +0800 Subject: [PATCH 2/2] Update default filesystem driver to public --- config/filesystems.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/filesystems.php b/config/filesystems.php index 4544f60..3141de0 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -13,7 +13,7 @@ return [ | */ - 'default' => env('FILESYSTEM_DRIVER', 'local'), + 'default' => env('FILESYSTEM_DRIVER', 'public'), /* |-------------------------------------------------------------------------- @@ -45,19 +45,19 @@ return [ 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), + 'root' => storage_path('app'), ], 'public' => [ - 'driver' => 'local', - 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'driver' => 'local', + 'root' => storage_path('app/public'), + 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ], 's3' => [ 'driver' => 's3', - 'key' => env('AWS_KEY'), + 'key' => env('AWS_KEY'), 'secret' => env('AWS_SECRET'), 'region' => env('AWS_REGION'), 'bucket' => env('AWS_BUCKET'),