Skip to content

Commit

Permalink
Merge pull request #8 from savannabits/development
Browse files Browse the repository at this point in the history
Bug Fix in HasTeam: referencing auth()->user()->team was causing null…
  • Loading branch information
coolsam726 authored Oct 22, 2023
2 parents c86a06c + 61983bd commit 24fd387
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Concerns/Model/HasTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ public static function bootHasTeam()
return;
}
if (Schema::hasColumn($query->getModel()->getTable(),'team_id')) {
$query->whereBelongsTo(auth()->user()->team)->orWhereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
$user = auth()->user();
if ($user) {
$query->whereBelongsTo($user->team)
->orWhereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
} else {
$query->whereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
}
}
// $query->where('team_id', auth()->user()->team_id);
// or with a `team` relationship defined:
Expand Down

0 comments on commit 24fd387

Please sign in to comment.