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
christmex
christmex9mo ago
can u show me the ListRecord code? when u call the delete action
tarifss
tarifssOP9mo ago
->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...
christmex
christmex9mo ago
can u comment the action? onyl leave this one
Tables\Actions\DeleteAction::make()->visible(auth()->user()->can('category_delete'))
Tables\Actions\DeleteAction::make()->visible(auth()->user()->can('category_delete'))
tarifss
tarifssOP9mo ago
its working without action group..but i need action group...previously its working but today new update is not working
christmex
christmex9mo ago
can u try this? replace your actionwith before
use Filament\Tables\Actions\Action;

->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();
}
})
use Filament\Tables\Actions\Action;

->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();
}
})
tarifss
tarifssOP9mo ago
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(); }), ]), ])
christmex
christmex9mo ago
no need to add the after function only before
tarifss
tarifssOP9mo ago
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(); } }), ]), ])
christmex
christmex9mo ago
hmm, thts weird got no access to the project, so kinda hard to find another way to help
tarifss
tarifssOP9mo ago
automatically solved by latest released
Want results from more Discord servers?
Add your server