Beispiel #1
0
 public static function boot()
 {
     parent::boot();
     //This event will delete all related model in category model
     static::deleted(function ($brand) {
         $r = $brand->categories()->lists('id');
         if (!empty($r)) {
             Productcategory::destroy($r);
         }
     });
     static::updated(function ($brand) {
         //$r = $brand->categories()->lists('id');
     });
 }
 public function deleteCategories()
 {
     $ids = explode(',', Input::get('javascriptArrayString'));
     //Log
     $cats = [];
     foreach ($ids as $id) {
         $cats[] = Productcategory::where('id', $id)->pluck('name');
     }
     $brandName = Productcategory::find($ids[0])->brand()->pluck('name');
     //Then temp delete them
     Productcategory::destroy($ids);
     if (!empty($cats)) {
         $log['products'] = "Category Belonging To <b class='orange'>" . $brandName . "</b> Brand = <b>" . implode(' | ', $cats) . '</b>';
         $log['stocktype'] = 'delete';
         $this->_saveActivityLog($log);
     }
     $data['status'] = 'success';
     $data['message'] = 'Deleted successfully';
     return Response::json($data);
 }