diff --git a/packages/admin/src/Filament/Resources/AttributeGroupResource.php b/packages/admin/src/Filament/Resources/AttributeGroupResource.php index 31296f6792..83adb54d47 100644 --- a/packages/admin/src/Filament/Resources/AttributeGroupResource.php +++ b/packages/admin/src/Filament/Resources/AttributeGroupResource.php @@ -8,6 +8,7 @@ use Filament\Support\Facades\FilamentIcon; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; use Lunar\Admin\Filament\Resources\AttributeGroupResource\Pages; use Lunar\Admin\Filament\Resources\AttributeGroupResource\RelationManagers; @@ -132,6 +133,8 @@ public static function getDefaultTable(Table $table): Table Tables\Actions\DeleteBulkAction::make(), ]), ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['attributes'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => ! $record->attributes_count) ->defaultSort('position', 'asc') ->reorderable('position'); } diff --git a/packages/admin/src/Filament/Resources/BrandResource.php b/packages/admin/src/Filament/Resources/BrandResource.php index 4e4294477d..65d5dfd083 100644 --- a/packages/admin/src/Filament/Resources/BrandResource.php +++ b/packages/admin/src/Filament/Resources/BrandResource.php @@ -12,6 +12,7 @@ use Filament\Tables\Columns\SpatieMediaLibraryImageColumn; use Filament\Tables\Table; use Illuminate\Contracts\Support\Htmlable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Lunar\Admin\Filament\Resources\BrandResource\Pages; use Lunar\Admin\Support\Forms\Components\Attributes; @@ -109,7 +110,10 @@ public static function getDefaultTable(Table $table): Table Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), - ])->searchable(); + ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['products'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => ! $record->products_count) + ->searchable(); } protected static function getTableColumns(): array diff --git a/packages/admin/src/Filament/Resources/CollectionGroupResource.php b/packages/admin/src/Filament/Resources/CollectionGroupResource.php index 8df50bfd44..a0a513b804 100644 --- a/packages/admin/src/Filament/Resources/CollectionGroupResource.php +++ b/packages/admin/src/Filament/Resources/CollectionGroupResource.php @@ -8,6 +8,7 @@ use Filament\Support\Facades\FilamentIcon; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; use Lunar\Admin\Filament\Resources\CollectionGroupResource\Pages; use Lunar\Admin\Support\Resources\BaseResource; @@ -101,7 +102,9 @@ public static function table(Table $table): Table Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), - ]); + ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['collections'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => ! $record->collections_count); } protected static function getTableColumns(): array diff --git a/packages/admin/src/Filament/Resources/CustomerGroupResource.php b/packages/admin/src/Filament/Resources/CustomerGroupResource.php index 520b3ec583..93fc399b38 100644 --- a/packages/admin/src/Filament/Resources/CustomerGroupResource.php +++ b/packages/admin/src/Filament/Resources/CustomerGroupResource.php @@ -9,6 +9,7 @@ use Filament\Support\Facades\FilamentIcon; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Lunar\Admin\Filament\Resources\CustomerGroupResource\Pages; use Lunar\Admin\Support\Forms\Components\Attributes; @@ -97,7 +98,9 @@ public static function getDefaultTable(Table $table): Table Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), - ]); + ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['customers'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => ! $record->customers_count); } protected static function getTableColumns(): array diff --git a/packages/admin/src/Filament/Resources/CustomerResource.php b/packages/admin/src/Filament/Resources/CustomerResource.php index 0419f0ff6a..a4e835e564 100644 --- a/packages/admin/src/Filament/Resources/CustomerResource.php +++ b/packages/admin/src/Filament/Resources/CustomerResource.php @@ -196,6 +196,8 @@ protected static function getDefaultTable(Table $table): Table Tables\Actions\DeleteBulkAction::make(), ]), ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['addresses', 'users', 'orders'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => ! ($record->addresses_count || $record->users_count || $record->orders_count)) ->selectCurrentPageOnly(); } diff --git a/packages/admin/src/Filament/Resources/ProductOptionResource.php b/packages/admin/src/Filament/Resources/ProductOptionResource.php index ab8dabef06..974879434a 100644 --- a/packages/admin/src/Filament/Resources/ProductOptionResource.php +++ b/packages/admin/src/Filament/Resources/ProductOptionResource.php @@ -113,6 +113,11 @@ public static function getDefaultTable(Table $table): Table Tables\Actions\DeleteBulkAction::make(), ]), ]) + ->modifyQueryUsing( + fn ($query) => $query->shared() + ) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['values'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => $record->values_count == 0) ->searchable(); } diff --git a/packages/admin/src/Filament/Resources/ProductTypeResource.php b/packages/admin/src/Filament/Resources/ProductTypeResource.php index 509f2cacba..c40fa3fd50 100644 --- a/packages/admin/src/Filament/Resources/ProductTypeResource.php +++ b/packages/admin/src/Filament/Resources/ProductTypeResource.php @@ -6,6 +6,7 @@ use Filament\Forms\Components\Component; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; use Lunar\Admin\Filament\Resources\ProductTypeResource\Pages; use Lunar\Admin\Support\Forms\Components\AttributeSelector; use Lunar\Admin\Support\Resources\BaseResource; @@ -104,7 +105,9 @@ public static function getDefaultTable(Table $table): Table Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), - ]); + ]) + ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['products'])) + ->checkIfRecordIsSelectableUsing(fn ($record): bool => $record->products_count == 0); } protected static function getTableColumns(): array