From 94e868ebaaf9264477e1d3621be3472c961157ca Mon Sep 17 00:00:00 2001 From: TinaH Date: Wed, 12 Jan 2022 17:39:53 +0100 Subject: [PATCH] Avoid problems with seeders and factories It is not always a logged in user that creates a team. In seeders, tests and factories, I set the $model->owner_id manually and I get an error from this class. This change prevents that. ```php $model->owner_id = $model->owner_id ?? auth()->user()->getKey(); ``` --- src/Models/TeamworkTeam.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/TeamworkTeam.php b/src/Models/TeamworkTeam.php index 2ab0bc9..b02de64 100755 --- a/src/Models/TeamworkTeam.php +++ b/src/Models/TeamworkTeam.php @@ -56,7 +56,7 @@ protected static function boot() static::creating(function ($model) { $model->uuid = (string)Uuid::uuid1(); $model->slug = Str::slug($model->name); - $model->owner_id = auth()->user()->getKey(); + $model->owner_id = $model->owner_id ?? auth()->user()->getKey(); }); static::updating(function ($model) {