dimanche 18 octobre 2015

How to listed to deleted event properly?

I have records of a model that I need to delete, however I need to delete their Ids also from the pivot table, so I tried to listed to deleted event, but it didn't work

Here is how I add the event:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Criteria extends Model {

    protected $table = 'criterias';

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

        static::deleted(function($criteria)
        {
            DB::table('criteria_criteria')->where('criteria_id', '=', $criteria->id)->delete();
        });

    }


}

I am on Laravel 5.1, any idea how to do so?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire