diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index cfa611e827..f8790af34a 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -181,9 +181,16 @@ class CategoriesController extends Controller if ($category->has_models() > 0) { + return Redirect::to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_models')); - // Redirect to the asset management page - return Redirect::to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_users')); + } elseif ($category->accessories()->count() > 0) { + return Redirect::to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_accessories')); + + } elseif ($category->consumables()->count() > 0) { + return Redirect::to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_consumables')); + + } elseif ($category->components()->count() > 0) { + return Redirect::to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_components')); } else { $category->delete(); @@ -236,7 +243,7 @@ class CategoriesController extends Controller public function getDatatable() { // Grab all the categories - $categories = Category::with('assets', 'accessories', 'consumables'); + $categories = Category::with('assets', 'accessories', 'consumables','components'); if (Input::has('search')) { $categories = $categories->TextSearch(e(Input::get('search'))); @@ -267,12 +274,19 @@ class CategoriesController extends Controller $rows = array(); foreach ($categories as $category) { - $actions = ''; + + $actions = ''; + $actions .=''; + $actions .=''; $rows[] = array( 'id' => $category->id, 'name' => (string)link_to('/admin/settings/categories/'.$category->id.'/view', $category->name) , 'category_type' => ucwords($category->category_type), - 'count' => $category->assets->count(), + 'count' => $category->itemCount(), 'acceptance' => ($category->require_acceptance=='1') ? '' : '', //EULA is still not working correctly 'eula' => ($category->getEula()) ? '' : '', @@ -340,7 +354,7 @@ class CategoriesController extends Controller $inout=''; if ($asset->deleted_at=='') { - $actions = '
'; + $actions = '
'; } elseif ($asset->deleted_at!='') { $actions = ''; } diff --git a/resources/lang/en/admin/categories/message.php b/resources/lang/en/admin/categories/message.php index c4f947bd3f..1fc4665cbe 100755 --- a/resources/lang/en/admin/categories/message.php +++ b/resources/lang/en/admin/categories/message.php @@ -4,6 +4,11 @@ return array( 'does_not_exist' => 'Category does not exist.', 'assoc_users' => 'This category is currently associated with at least one model and cannot be deleted. Please update your models to no longer reference this category and try again. ', + 'assoc_accessories' => 'This category is currently associated with at least one accessory and cannot be deleted. Please update your accessories to no longer reference this category and try again. ', + 'assoc_consumables' => 'This category is currently associated with at least one consumable and cannot be deleted. Please update your consumables to no longer reference this category and try again. ', + 'assoc_component' => 'This category is currently associated with at least one component and cannot be deleted. Please update your components to no longer reference this category and try again. ', + + 'create' => array( 'error' => 'Category was not created, please try again.',