© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
28 replies
RT2023

Trait for user Model

Hi there , I have a multi tenant project the tenants are restaurant name and users belong to one restaurant. I want to show all the users from the user resource when the logged in user has a Admin role. Otherwise, managers can only see restaurants belonging to the user , restaurant_id.

I was able to write a trait that works great when i have users logged in. Once I sign out the user I get the following message.

the code of the trait is:



<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\Builder;

trait FilterByRestaurant
{
protected static function boot(): void
{

parent::boot();

$restaurantId = auth()->user()->restaurant_id;

self::creating(function($model) use ($restaurantId){
$model->restaurant_id=$restaurantId;
});

if ( ! auth()->user()->hasRole('Admin')) {
self::addGlobalScope(function(Builder $builder) use($restaurantId){
$builder->where('restaurant_id',$restaurantId);
});
}


}
}



Can you please help me to figure out what my issue is?

Thanks
image.png
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

New Trait on model blocking ProductResource Index Page
FilamentFFilament / ❓┊help
3y ago
Password reset for different user model
FilamentFFilament / ❓┊help
2y ago
Custom User model
FilamentFFilament / ❓┊help
3y ago
Admin Model instead of User model
FilamentFFilament / ❓┊help
9mo ago