Skip to content

Commit

Permalink
Bug Fix in HasTeam: referencing auth()->user()->team was causing null…
Browse files Browse the repository at this point in the history
…ability issues
  • Loading branch information
coolsam726 committed Oct 22, 2023
1 parent 628681a commit 61983bd
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 61983bd

Please sign in to comment.