From a4d3f55efcb953e871715f78324e1588398c7b5e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 24 Oct 2018 12:19:50 -0600 Subject: [PATCH 1/2] Update UserSetting model --- app/UserSetting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/UserSetting.php b/app/UserSetting.php index 3de9191db..a8c67739d 100644 --- a/app/UserSetting.php +++ b/app/UserSetting.php @@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model; class UserSetting extends Model { - // + protected $fillable = ['user_id']; } From b436ac2cbb304563627c6e41b322c1bdf73952fe Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 24 Oct 2018 12:20:16 -0600 Subject: [PATCH 2/2] Update UserObserver --- app/Observer/UserObserver.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Observer/UserObserver.php b/app/Observer/UserObserver.php index 78698cb25..cd8ca6094 100644 --- a/app/Observer/UserObserver.php +++ b/app/Observer/UserObserver.php @@ -6,6 +6,7 @@ use App\Jobs\AvatarPipeline\CreateAvatar; use App\Profile; use App\User; use App\UserSetting; +use DB; class UserObserver { @@ -41,9 +42,11 @@ class UserObserver } if (empty($user->settings)) { - $settings = new UserSetting(); - $settings->user_id = $user->id; - $settings->save(); + DB::transaction(function() use($user) { + UserSetting::firstOrCreate([ + 'user_id' => $user->id + ]); + }); } } }