Skip to content

Commit 94e868e

Browse files
authored
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(); ```
1 parent 325f37e commit 94e868e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Models/TeamworkTeam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected static function boot()
5656
static::creating(function ($model) {
5757
$model->uuid = (string)Uuid::uuid1();
5858
$model->slug = Str::slug($model->name);
59-
$model->owner_id = auth()->user()->getKey();
59+
$model->owner_id = $model->owner_id ?? auth()->user()->getKey();
6060
});
6161

6262
static::updating(function ($model) {

0 commit comments

Comments
 (0)