F
Filamentlucasdutra04

Filter using columns

Hello, I'm having difficulty creating a filter in a query that I inserted in the columns. How can I retrieve the filter values and insert them into the query? Filament v3.1 public static function table(Table $table): Table { return $table ->defaultSort('created_at', 'desc') ->columns([ Tables\Columns\TextColumn::make('name') ->searchable(), Tables\Columns\TextColumn::make('total') ->getStateUsing(function (Model $record) { //FILTER HERE >>>>>>>>>>>>>>>>>>>>>>> $filter = $filters['tableFilters']['created_at']; $from = $filter['created_from']; $to = $filter['created_until']; //END FILTER HERE >>>>>>>>>>>>>>>>>>>>>>> return Deposit::where('user_id', $record->id) ->where('status', 1) ->whereDate('created_at', '>=', isset($from) && $from != 'null' ? Carbon::parse($from) : date("Y-m-d")) ->whereDate('created_at', '<=', isset($to) && $to != 'null' ? Carbon::parse($to) : date("Y-m-d")) ->sum('amount'); }) ->label(trans('Total')), ]) ->filters([ Filter::make('created_at') ->form([ DatePicker::make('created_from')->label('Initial'), DatePicker::make('created_until')->label('Final'), ]) ->indicateUsing(function (array $data): array { // I REMOVED BECAUSE LENGHT 2000.......... }) ]); }
Solution:
@lucasdutra04 I got my issue fixed like this ``` return $table ->query(...
D
devspecter33d ago
any solution? @lucasdutra04
L
lucasdutra0433d ago
No
Solution
D
devspecter33d ago
@lucasdutra04 I got my issue fixed like this
return $table
->query(
function () {
$filters = $this->tableFilters;

$dateRange = [];
if (!empty($filters['created_at']['created_from'])) {
$dateRange['from'] = $filters['created_at']['created_from'];
}
if (!empty($filters['created_at']['created_to'])) {
$dateRange['to'] = $filters['created_at']['created_to'];
}

return MyService::myCustomQuery($dateRange);
}
)
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('name')->label('Name'),
...
])
->filters([
Tables\Filters\Filter::make('created_at')
->form([
DatePicker::make('created_from'),
DatePicker::make('created_to'),
])
]);
return $table
->query(
function () {
$filters = $this->tableFilters;

$dateRange = [];
if (!empty($filters['created_at']['created_from'])) {
$dateRange['from'] = $filters['created_at']['created_from'];
}
if (!empty($filters['created_at']['created_to'])) {
$dateRange['to'] = $filters['created_at']['created_to'];
}

return MyService::myCustomQuery($dateRange);
}
)
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('name')->label('Name'),
...
])
->filters([
Tables\Filters\Filter::make('created_at')
->form([
DatePicker::make('created_from'),
DatePicker::make('created_to'),
])
]);
Want results from more Discord servers?
Add your server
More Posts
Hiring a senior mobile app developer from India or PakistanI have some mobile projects. I want someone have over 3 years experience. And especially I hope reacGet current row record in custom action```php Tables\Actions\Action::make('make_additional_payment') ->label('Наплати дSelect multiple preloaded options are reordered after selecting the inputI have a select multiple that is formFilled with options already attached on a BelongsToMany relatioError on trying to edit or create a new role at SHIELD pluginIm getting ```count(): Argument #1 ($value) must be of type Countable|array, null given``` this errotesting repeater / fillForm / fill default itemHi - I'm just getting started writing tests for my app with Pest. My first and most high-traffic resUse fa-icon in table builderI'm working in a project who already have a database in production. The database have a table with aIs there a difference between these two `Auth::user()` vs `Filament::auth()->user()`?Is there anytime where using one or the other is beneficial?larazeus popover pop under table header/footerHello, having a problem, when i add a popover in a table, it's showing under the tablefooter/header.Laravel Breeze and filamentHi everyone, i use filament for the admin panel that is registered on /admin, then i have an api endSetting an input value from outside the repeater?I need to set some input's values from outside the repeater using afterStateUpdated but I can not geIs it possible to add custom variables for creating contracts in the Rich Editor?I need to create a contract template where variables such as names, addresses, and personal documentFilament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints():Hi guys .. i'm on ContratoResource file wich list contracts. Each contract can have one item created