Skip to content

Commit

Permalink
Avoid problems with seeders and factories
Browse files Browse the repository at this point in the history
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();
```
  • Loading branch information
tanthammar authored Jan 12, 2022
1 parent 325f37e commit 94e868e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Models/TeamworkTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 94e868e

Please sign in to comment.