chubbyk
chubbyk

Reputation: 6302

Eloquent deleting model event doesn't fire

I have 2 models defined:

Program model:

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');
    }
}

Description model, where description for the program is defined

class Description extends \Eloquent {

    protected $guarded = [];

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

When I delete Program with specific name I want the description for that program to be deleted too.

So:

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

Unfortunately this code doesn't fire "deleting" event for Program model and the description isn't deleted.

Whats wrong ?

Upvotes: 1

Views: 243

Answers (1)

chubbyk
chubbyk

Reputation: 6302

The solution is :

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

Upvotes: 1

Related Questions