Example #1
0
 public static function boot()
 {
     parent::boot();
     //validation on create
     static::creating(function ($customer) {
         return $customer->isValid();
     });
     //This event will delete all related model in category model
     static::deleted(function ($cs) {
         //Deletes all customerlog related to a customer
         $c = $cs->customerlog()->lists('id');
         if (!empty($c)) {
             Customerlog::destroy($c);
         }
         //Deletes all Receipt related to a customer
         $r = $cs->receipt()->lists('id');
         if (!empty($r)) {
             Receipt::destroy($r);
         }
         //Deletes all Salelog related to a customer
         $s = $cs->salelog()->lists('id');
         if (!empty($s)) {
             Salelog::destroy($s);
         }
     });
     //validation on update
     static::updating(function ($customer) {
         //return $customer->isValid();
     });
 }