Displaying data from query at Resource Page

I'm trying to display this data based on the $currentUser = $tradingprofile->pic_id i've been looking around should i use getTableQuery() ? i tried using it inside the Resource page but nothing works as well as List Page too.
3 Replies
alcmz
alcmzOP2y ago
as example image above; The current user id is 5 , therefore , current list should be showing only PIC NAME 5
krekas
krekas2y ago
How have you tried?
alcmz
alcmzOP2y ago
sorry forgotten to include these: i have tried the following inside Resource and List page getTableQuery() and getEloquentQuery() the table query was my random attempt while Eloquent was what i read from document
public function getTableQuery()
{
$user = auth()->user();
return TradingProfile::forUser($user->id);
}
public function getTableQuery()
{
$user = auth()->user();
return TradingProfile::forUser($user->id);
}
or
public static function getEloquentQuery(): Builder
{
$query = Tradingprofile::query();

$currentUser = auth()->user();
$hasRestrictedRoles = $currentUser->hasAnyRole(['super_admin', 'admin', 'Sales Manager']);

if (!$hasRestrictedRoles) {
// Assuming the relationship between User and TradingProfile is defined as `tradingProfiles`
$query->whereHas('customer', function (Builder $query) use ($currentUser) {
$query->where('user_id', $currentUser->id);
});
}

return $query;
}
public static function getEloquentQuery(): Builder
{
$query = Tradingprofile::query();

$currentUser = auth()->user();
$hasRestrictedRoles = $currentUser->hasAnyRole(['super_admin', 'admin', 'Sales Manager']);

if (!$hasRestrictedRoles) {
// Assuming the relationship between User and TradingProfile is defined as `tradingProfiles`
$query->whereHas('customer', function (Builder $query) use ($currentUser) {
$query->where('user_id', $currentUser->id);
});
}

return $query;
}
well the getTableQuery() throws arrow meanwhile getEloquentQuery() doesnt return anything my bad , i got it working after tinkering around with the code and yes we can use getEloquentQeury()
public static function getEloquentQuery(): Builder
{
$hasRestrictedRoles = auth()->user()->hasAnyRole(['super_admin' , 'admin' , 'operation']);
$currentUser = auth()->user()->id;
$query = Tradingprofile::query();


if (!$hasRestrictedRoles) {
$query->where('pic_id', $currentUser);
}
return $query;
}
public static function getEloquentQuery(): Builder
{
$hasRestrictedRoles = auth()->user()->hasAnyRole(['super_admin' , 'admin' , 'operation']);
$currentUser = auth()->user()->id;
$query = Tradingprofile::query();


if (!$hasRestrictedRoles) {
$query->where('pic_id', $currentUser);
}
return $query;
}
Want results from more Discord servers?
Add your server