public function getEditmedias($sid, $module_id) { $medias = Media::where('category_id', $sid)->orderBy('name')->get(); $memberships = Membership::orderBy('rank')->get(); $modMediaMembership = array(); foreach (ModuleMediaMembership::where('module_id', $module_id)->get() as $mmm) { $modMediaMembership[$mmm->media_id][$mmm->membership_id] = true; } return \View::make('redminportal::modules/medias')->with('medias', $medias)->with('memberships', $memberships)->with('modMediaMembership', $modMediaMembership); }
public function getDelete($sid) { // Find the category using the user id $category = Category::find($sid); if ($category == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category cannot be found because it does not exist or may have been deleted."); return redirect('/admin/categories')->withErrors($errors); } // Find if there's any child $children = Category::where('category_id', $sid)->count(); if ($children > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it has " . $children . " children categories."); return redirect('/admin/categories')->withErrors($errors); } // Check in use by media $medias = Media::where('category_id', $sid)->get(); if (count($medias) > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it is in used."); return redirect('/admin/categories')->withErrors($errors); } // Delete the category $category->delete(); return redirect('admin/categories'); }