Exemple #1
0
 public function hasChild()
 {
     $menu = MenuNode::whereParentId($this->id)->select('id')->first();
     if ($menu) {
         return true;
     } else {
         return false;
     }
 }
Exemple #2
0
 /**
  * @param $menu_content_id
  * @param $parent_id
  * @param null $selects
  * @return array|\Illuminate\Database\Eloquent\Collection|static[]
  */
 public function getMenuNodes($menu_content_id, $parent_id, $selects = null)
 {
     return MenuNode::where(['menu_content_id' => $menu_content_id, 'parent_id' => $parent_id])->select($selects)->orderBy('position', 'asc')->get();
 }
Exemple #3
0
 /**
  * @param $json_item
  * @param $menu_content_id
  * @param $parent_id
  * @return mixed
  */
 private function _saveMenuNode($json_item, $menu_content_id, $parent_id)
 {
     if (isset($json_item->id)) {
         $item = MenuNode::find($json_item->id);
     }
     if (!$item) {
         $item = new MenuNode();
     }
     $item->title = isset($json_item->title) ? $json_item->title : '';
     $item->url = isset($json_item->customurl) ? $json_item->customurl : '';
     $item->css_class = isset($json_item->class) ? $json_item->class : '';
     $item->position = isset($json_item->position) ? $json_item->position : '';
     $item->icon_font = isset($json_item->iconfont) ? $json_item->iconfont : '';
     $item->type = isset($json_item->type) ? $json_item->type : '';
     $item->menu_content_id = $menu_content_id;
     $item->parent_id = $parent_id;
     switch ($json_item->type) {
         case 'custom-link':
             $item->related_id = 0;
             break;
         default:
             $item->related_id = (int) $json_item->relatedid;
             break;
     }
     $item->save();
     return $item->id;
 }