How to use Eloquent's sushi, but the data is dynamic from API?

So, let's say I'm using a table filter, but its data is sourced from an API. Can we dynamically get the data? I reckon that using Sushi only allows you to source the data upfront. But I want to get the data dynamically based on table's filter
6 Replies
Patrick Boivin
Patrick Boivin16mo ago
getRows() should be called every time you change the filter/sort/etc. on the table. Are you running into any issues? OH, I think I misunderstood the question. You want to pass the active filters to Sushi, so they are included in the request to the API?
Ricardo Sawir
Ricardo SawirOP16mo ago
yes! do you have any idea on how to do that? the current way is to... use request('filter.any_filter')
Patrick Boivin
Patrick Boivin16mo ago
No! lol, don't use the request 1 sec, I can find an example for you. I'm not sure it's the best way, but it's how I'm doing it 🥴
Ricardo Sawir
Ricardo SawirOP16mo ago
call ->migrate() directly? 🥹
Patrick Boivin
Patrick Boivin16mo ago
Here's a previous thread for reference. Not related to your issue directly but can be useful if you want to dig deeper: https://discord.com/channels/883083792112300104/1120914138919612428/1121138618333929582 This is how I'm passing parameters to my Sushi models:
class ProductCompatibleVehicle extends Model
{
use Sushi;

protected static array $vehicle_ids = [];

public static function queryForVehicleIds(array $ids): Builder
{
static::$vehicle_ids = $ids;

return static::query();
}

public function getRows()
{
if (!self::$vehicle_ids) {
return [];
}

// ... prepare rows ...

return $rows;
}
}
class ProductCompatibleVehicle extends Model
{
use Sushi;

protected static array $vehicle_ids = [];

public static function queryForVehicleIds(array $ids): Builder
{
static::$vehicle_ids = $ids;

return static::query();
}

public function getRows()
{
if (!self::$vehicle_ids) {
return [];
}

// ... prepare rows ...

return $rows;
}
}
In this example, I'm passing a list of IDs to take into account in my getRows() method:
protected function getTableQuery(): Builder
{
return ProductCompatibleVehicle::queryForVehicleIds($this->vehicle_ids);
}
protected function getTableQuery(): Builder
{
return ProductCompatibleVehicle::queryForVehicleIds($this->vehicle_ids);
}
Ricardo Sawir
Ricardo SawirOP16mo ago
Oh nice!
Want results from more Discord servers?
Add your server