Php 确定是否是事件处理程序Laravel中的软删除

Php 确定是否是事件处理程序Laravel中的软删除,php,laravel,Php,Laravel,我有一个事件处理程序: protected static function boot() { parent::boot(); static::deleting(function($user) { // before delete() method call this $user->comments()->delete(); }); } 当我使用$user->forceDelete()时和$user->delete()触发此事件并删除所有注

我有一个事件处理程序:

protected static function boot() {
    parent::boot();

    static::deleting(function($user) { // before delete() method call this
        $user->comments()->delete();

    });
}

当我使用
$user->forceDelete()时
$user->delete()触发此事件并删除所有注释。这不正常,因为我希望仅在
$user->forceDelete()上触发此事件。在我的情况下,其他表没有实现软删除

您可以检查模型上的
forceDeleting
属性。如果您正在执行
forceDelete

static::deleting(function($user) { // before delete() method call this
    if ($user->forceDeleting) {
        $user->comments()->delete();
    }
});
在模型类中(作为示例):


对于Laravel 5.4+使用
$user->isForceDeleting()
,因为
forceDeleting
属性现在具有受保护的可见性。如何获取request()->示例值?
public static function boot() {
    
    parent::boot();
    
    static::created(function($item){
        Log::info("Model Created:".get_class($item)."-ID-".$item->id.'-by user: '.Auth::id());
    });
    
    static::updated(function($item){
        Log::info("Model Updated:".get_class($item)."-ID-".$item->id.'-by user: '.Auth::id());
    });
    
    static::deleted(function($item){
        Log::info("Model Soft Delete:".get_class($item)."-ID-".$item->id.'-by user: '.Auth::id());
    });

    static::forceDeleted(function($item){
        Log::info("Model Force Delete:".get_class($item)."-ID-".$item->id.'-by user: '.Auth::id());
    });
    
}