Custom Bulkaction generate duplicate queries
Hi i'm trying to add a custom bulkaction to a products table but i'm getting duplicate queries
here's my code
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
])
->bulkActions([
Tables\Actions\BulkAction::make('bulk_updates')
->action(function ($livewire, $data, $records) {
//...
})
->form(
function ($records, $data) {
return [
Forms\Components\Select::make('periode')
->label('Période')
->options(fn () => Periode::pluck('name', 'id'))
->required(),
];
}
),
]);
}
am i doing something wrong here ?
32 Replies
@Dan Harrin any suggestion please ?
i dont have any suggestions, sorry
The code you posted seems ok. But I feel like you’re not showing something that could be the cause.
I agree with awcodes, post your entire class. If you have filters for example that are not arrow functions it will repeat and so on.
@awcodes @toeknee_iom here's the class
class ProduitResource extends Resource
{
protected static ?string $model = Produit::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
public static function form(Form $form): Form
{
return $form
->schema([
Card::make()->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
])
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
])
->bulkActions([
Tables\Actions\BulkAction::make('bulk_updates')
->action(function ($livewire, $data, $records) {
//...
})
->form(
function ($records, $data) {
return [
Forms\Components\Select::make('periode')
->label('Période')
->options(fn () => Periode::pluck('name', 'id'))
->required(),
];
}
),
]);
}
public static function getRelations(): array
{
return [
VenteManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListProduits::route('/'),
'create' => Pages\CreateProduit::route('/create'),
'edit' => Pages\EditProduit::route('/{record}/edit'),
];
}
}
Do you have widgets on the page?
I can't replicate so many calls like that, so something else appears to be going on.
@toeknee_iom no widgets on the page
@Dan Harrin @awcodes @toeknee_iom
here's on github
https://github.com/Mambi/filament.git
GitHub
GitHub - Mambi/filament
Contribute to Mambi/filament development by creating an account on GitHub.
Try removing the function in ->form() and just use the array directly ->form([…..])
@awcodes tried but same result
Wasn’t sure. I’m really not seeing anything suspicious.
@toeknee_iom any chance ?
I’m thinking it might be a recursion issue where you are using a select to load options for the model your resource bulk action is trying to manipulate. What I’m getting at is I don’t understand the select in the form for a bulk action on the same model as your records.
@awcodes even if i change the select with a simple TextInput, i'm getting the same issue
What happens if you remove the bulk action completely? Just trying to think of ways to isolate the problem.
@awcodes if i don't use the bulk action i'm getting only 3 queries ,
That’s so odd. Can you try a ‘php artisan optimize:clear’
Wish I had a direct answer for you. Sorry.
Also, are you using valet?
i did php artisan optimize:clear + php artisan cahce:clear same thing
no i'm not using valit
Just wondering if there’s a cache somewhere that may be outside filament or laravel.
Been having some weird issues with valet myself recently. That’s why I ask.
can you clone the repo and make a test if possible
Sure, won’t be tonight, but I can try it tomorrow as long as you have seeders in place so I don’t have to create the data.
i'll add a seeder and let you know
Sounds good.
thanks a lot for your time
Definitely something odd going on.
yep
@awcodes As discussed, i added the ProduitSeeder (with random faker names) + the migration
Ok. Just waking up here. Will find some time to look at it today.
great
I'm seeing the same on my end with your repo. Not sure why the query is getting called 5 times. Might be a bug.
should i report it as a bug ?
sure. and just use that repo for the issue.
ok, once again thanks for your time