Skip to content

Commit

Permalink
fix n+1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagof committed Aug 26, 2024
1 parent 114164b commit 6ac2be0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Filament/Resources/RuleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Squarebit\FilamentVolition\Facades\FilamentVolition;
use Squarebit\FilamentVolition\Filament\Resources\RuleResource\Pages;
use Squarebit\FilamentVolition\Filament\Resources\RuleResource\RelationManagers;
Expand All @@ -16,6 +17,12 @@ class RuleResource extends Resource
{
protected static ?string $model = Rule::class;

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withCount(['conditions', 'actions']);
}

public static function form(Form $form): Form
{
return $form
Expand All @@ -38,11 +45,11 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('conditions')
->label(__('Conditions'))
->badge()
->getStateUsing(fn (Rule $record) => $record->conditions->count()),
->getStateUsing(fn (Rule $record) => $record->conditions_count),
Tables\Columns\TextColumn::make('actions')
->label(__('Actions'))
->badge()
->getStateUsing(fn (Rule $record) => $record->actions->count()),
->getStateUsing(fn (Rule $record) => $record->actions_count),

])
->filters([
Expand Down

0 comments on commit 6ac2be0

Please sign in to comment.