I am working with filament php and I am stuck here as I want table data to be user specific and want to get loggedin user data only
public static function table(Table $table): Table
{
$user = Auth::user(); // Get the authenticated user
$userId = $user->id; // Assuming 'id' is the user ID field in your user model
return $table //I want to access this data by user ID
->columns([
Tables\Columns\TextColumn::make('user_id')
->searchable(),
Tables\Columns\TextColumn::make('title')
->searchable(),
Tables\Columns\TextColumn::make('slug')
->searchable(),
Tables\Columns\TextColumn::make('status')
->searchable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
You can simply use
modifyQueryUsing
method on a Table instance.Read here for more.
For your use case it will be:
But I suggest If you just use the
user_id
for this filtering, move it to the scope of the query modifier function instead of initiating it out of the scope and then using it in the function. Something like this: