Delete action is not working
today when composer update then the issue created in filament v3.2.51
Filament\Resources\Pages\ListRecords::Filament\Resources\Pages{closure}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in /var/www/html/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
10 Replies
can u show me the ListRecord code? when u call the delete action
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make()->visible(auth()->user()->can('category_update')),
Tables\Actions\DeleteAction::make()->visible(auth()->user()->can('category_delete'))
->action(function (Category $record) {
if ($record->products()->exists() || $record->childrens()->exists()) {
Notification::make()
->title('Can't delete')
->body('' . $record->name . ' Category Added to a Product or has children')
->danger()
->send();
return;
} else {
$record->delete();
Notification::make()
->title('Delete')
->body('' . $record->name . ' Category Deleted')
->danger()
->send();
}
}),
]),
])
when remove ActionGroup then its working...
can u comment the action? onyl leave this one
its working without action group..but i need action group...previously its working but today new update is not working
can u try this? replace your actionwith before
got this error again for this code Filament\Resources\Pages\ListRecords::Filament\Resources\Pages{closure}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in /var/www/html/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make('category_update')->visible(auth()->user()->can('category_update')),
Tables\Actions\DeleteAction::make('category_delete')->visible(auth()->user()->can('category_delete'))
->before(function (Action $action,Category $record) {
if ($record->products()->exists() || $record->childrens()->exists()){
Notification::make()
->title("Can't delete")
->body('' . $record->name . ' Category Added to a Product or has children')
->danger()
->send();
$action->halt();
}
})
->after(function (Action $action,Category $record) {
$record->delete();
Notification::make()
->title('Delete')
->body('' . $record->name . ' Category Deleted')
->danger()
->send();
}),
]),
])
no need to add the after function
only before
not working if after removed
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make('category_update')->visible(auth()->user()->can('category_update')),
Tables\Actions\DeleteAction::make('category_delete')->visible(auth()->user()->can('category_delete'))
->before(function (Action $action,Category $record) {
if ($record->products()->exists() || $record->childrens()->exists()){
Notification::make()
->title("Can't delete")
->body('' . $record->name . ' Category Added to a Product or has children')
->danger()
->send();
$action->halt();
}
}),
]),
])
hmm, thts weird
got no access to the project, so kinda hard to find another way to help
automatically solved by latest released