public static function boot() { parent::boot(); self::deleting(function ($category) { $categories_id = $category->descendants()->lists('id'); $categories_id[] = $category->getKey(); $products = Product::whereHas('categories', function ($q) use($categories_id) { $q->whereIn('categories.id', $categories_id); })->get(); if ($category->getDescendantCount() > 0) { $html = "This category has children, you can't delete this category until you removed all the children"; \Session::flash('errorMsg', $html); return false; } else { if ($products->count() > 0) { $html = "Cannot delete this category due to still has related product(s).<br>\n"; $html .= "<ul>\n"; foreach ($products as $product) { $html .= " <li>{$product->name}</li>\n"; } $html .= "</ul>\n"; \Session::flash('errorMsg', $html); return false; } } }); }
/** * Get patch for columns. * * @since 2.0 * * @param array $params * * @return array */ protected function patch(array $params) { $grammar = $this->query->getGrammar(); $columns = array(); foreach ([$this->model->getLftName(), $this->model->getRgtName()] as $col) { $columns[$col] = $this->columnPatch($grammar->wrap($col), $params); } return $columns; }
public static function boot() { parent::boot(); Category::deleting(function ($category) { if (count($category->children) || count($category->products)) { Session::flash('error', 'Сначало удалите подкатегории и товары!'); return false; } }); }
/** * Get whether the node is an ancestor of other node, including immediate parent. * * @param Node $other * * @return bool */ public function isAncestorOf(Node $other) { return $other->isDescendantOf($this); }
/** * Fixes nodes tree * * @return Redirect */ public function fixNodesTree() { \Kalnoy\Nestedset\Node::fixTree(); $this->notify('maintenance.fixed_nodes_tree'); return redirect()->back(); }