How can I populate table based on user id?

For example, in my table I have 3 rows a,b,user_id. I want to be able to fill the table with rows that have the same user_id?
Solution:
Fix:
->query(Attribute::where('user_id', $user->id))
->query(Attribute::where('user_id', $user->id))
...
Jump to solution
2 Replies
DarkKnight
DarkKnightOP13mo ago
<?php

namespace App\Filament\Pages;

//...

class Test extends Page implements HasForms, HasActions, HasTable
{
use InteractsWithActions;
use InteractsWithForms;
use HasPageShield;
use InteractsWithTable;

// ...

public static function getEloquentQuery(): Builder
{
$user = auth()->user();
$query = parent::getEloquentQuery();
dd($query);
// Filter the query to show only records where `user_id` is the same as the authenticated user's ID.
return $query->where('user_id', $user->id);
}

public function table(Table $table): Table
{
return $table
->query(Attribute::query())
->columns([
TextColumn::make(''),
TextColumn::make(''),
TextColumn::make('user.name'),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
<?php

namespace App\Filament\Pages;

//...

class Test extends Page implements HasForms, HasActions, HasTable
{
use InteractsWithActions;
use InteractsWithForms;
use HasPageShield;
use InteractsWithTable;

// ...

public static function getEloquentQuery(): Builder
{
$user = auth()->user();
$query = parent::getEloquentQuery();
dd($query);
// Filter the query to show only records where `user_id` is the same as the authenticated user's ID.
return $query->where('user_id', $user->id);
}

public function table(Table $table): Table
{
return $table
->query(Attribute::query())
->columns([
TextColumn::make(''),
TextColumn::make(''),
TextColumn::make('user.name'),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
Solution
DarkKnight
DarkKnight13mo ago
Fix:
->query(Attribute::where('user_id', $user->id))
->query(Attribute::where('user_id', $user->id))
Want results from more Discord servers?
Add your server