Leander_ac
Leander_ac
FFilament
Created by Leander_ac on 12/7/2023 in #❓┊help
Getting table data from api with parameter from the logged in user
Hi! Im having trouble getting the package calebporzio/sushi to get my data and display it in my resource. Here is my code: Application Model
class Application extends Authenticatable
{
use Sushi;

protected static array $municipality_id = [];

public static function queryForMunicipalityId($id): Builder
{
static::$municipality_id = [$id];

return static::query();
}

public function getRows()
{
if (!static::$municipality_id) {
return [];
}

$applications = Http::get(env('ERP_URL').'applications/'.static::$municipality_id)->json();

return $applications['data'];
}
}
class Application extends Authenticatable
{
use Sushi;

protected static array $municipality_id = [];

public static function queryForMunicipalityId($id): Builder
{
static::$municipality_id = [$id];

return static::query();
}

public function getRows()
{
if (!static::$municipality_id) {
return [];
}

$applications = Http::get(env('ERP_URL').'applications/'.static::$municipality_id)->json();

return $applications['data'];
}
}
In the ApplicationResource i have this function:
public static function getEloquentQuery(): Builder
{
return Application::queryForMunicipalityId(auth()->user()->municipality_id);
}
public static function getEloquentQuery(): Builder
{
return Application::queryForMunicipalityId(auth()->user()->municipality_id);
}
I also tried this in the MangeApplication Page like this:
protected function getTableQuery(): Builder
{
return Application::queryForMunicipalityId(auth()->user()->municipality_id);
}
protected function getTableQuery(): Builder
{
return Application::queryForMunicipalityId(auth()->user()->municipality_id);
}
The api works fine if hardcode the ID in the url of the api (without the if statement) but the getRows does not seem to get fired again even when i'm applying filters or something. I used this example: https://discord.com/channels/883083792112300104/1138671423586566184/1138853947713532014 Does anyone know if it is possible to get the table data with information from the logged in user? If you need more information please let me know!
3 replies