Limiting Filament Table to User-Accessible in resource

Hello! How are you? I have a resource called SchoolResource for my School model. But I need only the schools that the user has permission to view to appear in the resource table. I already have a very simple method that does this, but I don't know how to limit the filament table.
public EloquentCollection|Collection $records;

public function mount(): void
{
$this->records = auth()->user()->schools();
}

public static function form(Form $form): Form
{
return $form
->schema(
[
//Abstracted............
]
)->columns(3);
}
public EloquentCollection|Collection $records;

public function mount(): void
{
$this->records = auth()->user()->schools();
}

public static function form(Form $form): Form
{
return $form
->schema(
[
//Abstracted............
]
)->columns(3);
}
Solution:
in the resource override the query and add a scope or a where: ```php public static function getEloquentQuery(): Builder {...
Jump to solution
5 Replies
krekas
krekas8mo ago
Your code isn't from a resource but looks like from a custom page
MK | Programmer
MK | ProgrammerOP8mo ago
It is indeed from a resource, I abstracted the code.
Solution
toeknee
toeknee8mo ago
in the resource override the query and add a scope or a where:
public static function getEloquentQuery(): Builder
{
$query = parent::getEloquentQuery()-->withGlobalScope(
SoftDeletingScope::class,
);

return $query;
}
public static function getEloquentQuery(): Builder
{
$query = parent::getEloquentQuery()-->withGlobalScope(
SoftDeletingScope::class,
);

return $query;
}
krekas
krekas8mo ago
What's with the mount then?
MK | Programmer
MK | ProgrammerOP8mo ago
I got it with this
Want results from more Discord servers?
Add your server