From 679f4310bd175430069ae3231218bac40c31c28d Mon Sep 17 00:00:00 2001 From: Andrey Dmitrakovich Date: Wed, 4 Dec 2024 20:22:32 +0300 Subject: [PATCH] 54. Improves user table filters Enhances the user table filters by grouping date pickers within fieldsets for better organization and improved user experience. Adds a new filter for user registration date. --- .../Filament/Resources/User/UserResource.php | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/src/app/Filament/Resources/User/UserResource.php b/src/app/Filament/Resources/User/UserResource.php index 52ae1e2b..0e8cdf46 100644 --- a/src/app/Filament/Resources/User/UserResource.php +++ b/src/app/Filament/Resources/User/UserResource.php @@ -166,7 +166,9 @@ public static function table(Table $table): Table ->boolean() ->sortable(), Tables\Columns\TextColumn::make('email') - ->label('E-mail'), + ->label('E-mail') + ->toggleable() + ->toggledHiddenByDefault(), Tables\Columns\TextColumn::make('phone') ->label('Телефон'), Tables\Columns\TextColumn::make('orders') @@ -206,17 +208,19 @@ public static function table(Table $table): Table ->falseLabel('Только оффлайн заказы'), Tables\Filters\Filter::make('order_date') ->form([ - DatePicker::make('ordered_from') - ->label('Совершали покупки с:') - ->native(false) - ->closeOnDateSelection(), - DatePicker::make('ordered_until') - ->label('Совершали покупки по:') - ->native(false) - ->closeOnDateSelection(), + Fieldset::make() + ->label('Совершали покупки') + ->schema([ + DatePicker::make('ordered_from') + ->label('с:') + ->native(false) + ->closeOnDateSelection(), + DatePicker::make('ordered_until') + ->label('по:') + ->native(false) + ->closeOnDateSelection(), + ]) ]) - ->columns() - ->columnSpan(2) ->query(function (Builder $query, array $data) { if (!$data['ordered_from'] && !$data['ordered_until']) { return; @@ -232,17 +236,19 @@ public static function table(Table $table): Table }), Tables\Filters\Filter::make('birth_date') ->form([ - DatePicker::make('birth_date_from') - ->label('День рождения с:') - ->native(false) - ->closeOnDateSelection(), - DatePicker::make('birth_date_until') - ->label('День рождения по:') - ->native(false) - ->closeOnDateSelection(), + Fieldset::make() + ->label('День рождения') + ->schema([ + DatePicker::make('birth_date_from') + ->label('с:') + ->native(false) + ->closeOnDateSelection(), + DatePicker::make('birth_date_until') + ->label('по:') + ->native(false) + ->closeOnDateSelection(), + ]) ]) - ->columns() - ->columnSpan(2) ->query(function (Builder $query, array $data) { if ($data['birth_date_from']) { $from = Carbon::parse($data['birth_date_from']); @@ -267,6 +273,29 @@ public static function table(Table $table): Table }); } }), + Tables\Filters\Filter::make('register_date') + ->form([ + Fieldset::make() + ->label('Дата регистрации') + ->schema([ + DatePicker::make('registered_from') + ->label('с:') + ->native(false) + ->closeOnDateSelection(), + DatePicker::make('registered_until') + ->label('по:') + ->native(false) + ->closeOnDateSelection(), + ]) + ]) + ->query(function (Builder $query, array $data) { + if ($data['registered_from']) { + $query->where('created_at', '>=', $data['registered_from']); + } + if ($data['registered_until']) { + $query->where('created_at', '<=', $data['registered_until']); + } + }), QueryBuilder::make() ->constraints([ TextConstraint::make('first_name')->label('Имя'),