2014-11-08 29 views
1

我有2款規定:雄辯刪除模型不會觸發事件

程序模型:

class Program extends \Eloquent { 

    protected $guarded = []; 

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

     static::deleting(function($program) 
     { 
      DB::table('descriptions')->where('id',$program->id)->delete(); 
      return true; 

     }); 
    } 

    public function description() 
    { 
     return $this->hasOne('Description'); 
    } 
} 

描述模型,其中被定義爲節目描述

class Description extends \Eloquent { 

    protected $guarded = []; 

    public function program() 
    { 
     return $this->belongsTo('Program','id','id'); 
    } 
} 

當我刪除具有特定名稱的程序我希望該程序的描述也被刪除。

所以:

Program::where('name',Input::get('name'))->delete(); 

不幸的是這個代碼不火「刪除」事件的計劃模型和描述不會被刪除。

怎麼了?

回答

1

解決的辦法是:

Program::where('name',Input::get('name'))->first()->delete(); 
+0

我想這是每點擊此鏈接:https://github.com/laravel/framework/issues/2536,但它仍然無法爲我工作。 – V4n1ll4 2015-09-03 15:10:41