-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Labels
Description
Laravel Version
11.31
PHP Version
8.4.3
Database Driver & Version
No response
Description
The forceDelete() method does not delete a model when it has an observer. The method returns true and updates the model's created_at timestamp to the current date and time. You must use forceDeleteQuietly() to delete a model.
Steps To Reproduce
Model:
#[ ObservedBy( [ DemandObserver::class ] ) ]
class Demand extends Model
{
use SoftDeletes;
......
}
Controller:
public function deletePermanently( Demand $demand )
{
if ( auth()->user()->can( 'forceDelete', $demand ) ){
$deleted = $demand->forceDelete();
return $deleted ? back()->with( 'success', 'The demand has been permanently removed.' ) : back()->withErrors( [ 'error' => 'The demand was not deleted.' ] );
}
return back()->withErrors( [ 'error' => 'You do not have permission to perform this operation.' ] );
}
Firing the deletePermanently() function return 'success', but the model is not deleted and created_at timestamp IS UPDATED.