You’ll want to use a custom Sprunje filter here. The name of your ufTable column does not necessarily need to correspond to a database table column. You can define a custom field name instead (e.g. asset_info
) and that will be submitted in the request instead:
GET http://localhost/userfrosting/public/api/items?size=5&page=0&filters[asset_info]=asc
By default, Sprunje will try to filter on a database column with the same name, which would cause an error because there is no asset_info
column in the base query table. So, we define a custom filter in our Sprunje which maps this new property identifier to a custom Eloquent clause:
/**
* Filter LIKE the asset_id or asset_name
*
* @param Builder $query
* @param mixed $value
* @return $this
*/
protected function filterAssetInfo($query, $value)
{
$query->like('asset_id', $value)
->orLike('asset_name', $value);
return $this;
}
Don’t forget to add asset_info
to your $filterable
whitelist. Sprunje will automatically take the asset_info
query parameter that gets sent from your ufTable
, and map it to this filterAssetInfo
method.