lucasdutra04
lucasdutra04
FFilament
Created by lucasdutra04 on 3/7/2024 in #❓┊help
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.......... }) ]); }
6 replies