Ejemplo n.º 1
0
 public function getDelete($id)
 {
     // Find the module using the user id
     $module = Module::find($id);
     if ($module == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "We are having problem deleting this entry. Please try again.");
         return \Redirect::to('admin/modules')->withErrors($errors);
     }
     $purchases = UserPricelist::join('pricelists', 'pricelists.id', '=', 'user_pricelists.pricelist_id')->where('pricelists.module_id', $id)->get();
     if (count($purchases) > 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "This module has been purchased before. You cannot delete it. Please change disable it instead.");
         return \Redirect::to('admin/modules')->withErrors($errors);
     }
     // Delete all images first
     $module->deleteAllImages();
     // Delete all tags
     $module->deleteAllTags();
     // Delete all pricelist
     foreach (Pricelist::where('module_id', $id)->get() as $pricelist) {
         $pricelist->delete();
     }
     // Delete all media links
     foreach (ModuleMediaMembership::where('module_id', $id)->get() as $mmm) {
         $mmm->delete();
     }
     // Delete the module
     $module->delete();
     return \Redirect::to('admin/modules');
 }