Soldges
auth()->check is false
Maybe the problem is that I add the trait to the user model and the traits tries to fetch the authenticated user but for this it needs to boot the user model and thats an loop...
Hmm... In my other plain laravel 10 app without Filament it works without any problem
16 replies
auth()->check is false
In the docs
https://filamentphp.com/docs/3.x/panels/tenancy#simple-one-to-many-tenancy
It it also outside the closure
use Illuminate\Database\Eloquent\Builder;
class Post extends Model
{
protected static function booted(): void
{
if (auth()->check()) {
static::addGlobalScope('team', function (Builder $query) {
$query->where('team_id', auth()->user()->team_id);
// or with a
team
relationship defined:
$query->whereBelongsTo(auth()->user()->team);
});
}
}
}16 replies
auth()->check is false
That was just my example. Here is the code and it is inside the closure but still false
public static function bootBelongsToTeam()
{
if (auth()->check()) {
static::creating(function ($model) {
$model->team_id = auth()->user()->team->id;
});
static::addGlobalScope('team_id', function (Builder $builder) {
return $builder->where('team_id', auth()->user()->team->id);
});
}
}
16 replies
auth()->check is false
hmmm.. Okay. Then I have to try this solution:
https://filamentphp.com/docs/3.x/panels/tenancy#simple-one-to-many-tenancy
I thought it would be better and more flexible in a Trait than directly in the model
16 replies