records based on roles

hi i want in resource if user has client role just see the record that belongs to him and if user has the role of operator see all records can any one help me?
6 Replies
Dennis Koch
Dennis Koch2y ago
Overwrite getEloquentQuery() on the Resource.
saeed
saeedOP2y ago
Could not check compatibility between App\Filament\Resources\AsnadResource::getEloquentQuery(): App\Filament\Resources\Builder and Filament\Resources\Resource::getEloquentQuery(): Illuminate\Database\Eloquent\Builder, because class App\Filament\Resources\Builder is not available i want to do this but i get this error and when i use use Illuminate\Database\Eloquent\Builder; i get this Class "App\Filament\Resources\AsnadResource\Pages\Actions\CreateAction" not found i'm sorry
Dennis Koch
Dennis Koch2y ago
You didn't import the builder. You can't just add code. You need to make sure it uses the right classes
saeed
saeedOP2y ago
is this modifi correct return static::getModel()::query()->where('user_id', Auth::user()->id); you right
Vp
Vp2y ago
try this
use Illuminate\Database\Eloquent\Builder;

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->where('your condition');
}
use Illuminate\Database\Eloquent\Builder;

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->where('your condition');
}
saeed
saeedOP2y ago
thank you

Did you find this page helpful?