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 + ]); + }); } } } 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']; }