Yab\Quarx\Repositories\LinkRepository::getLinksByMenuID PHP Method

getLinksByMenuID() public static method

Find Links by menu id.
public static getLinksByMenuID ( integer $id ) : Collection | null | static | Links
$id integer
return Illuminate\Support\Collection | null | static | Links
    public static function getLinksByMenuID($id)
    {
        return Link::where('menu_id', $id)->get();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Get a view.
  *
  * @param string $slug
  * @param View   $view
  *
  * @return string
  */
 public function menu($slug, $view = null)
 {
     $pageRepo = new PageRepository();
     $menu = MenuRepository::getMenuBySLUG($slug)->first();
     if (!$menu) {
         return '';
     }
     $links = LinkRepository::getLinksByMenuID($menu->id);
     $response = '';
     foreach ($links as $link) {
         if ($link->external) {
             $response .= "<a href=\"{$link->external_url}\">{$link->name}</a>";
         } else {
             $page = $pageRepo->findPagesById($link->page_id);
             $response .= '<a href="' . URL::to('page/' . $page->url) . "\">{$link->name}</a>";
         }
     }
     if (!is_null($view)) {
         $response = view($view, ['links' => $links, 'linksAsHtml' => $response]);
     }
     if (Gate::allows('quarx', Auth::user())) {
         $response .= '<a href="' . url('quarx/menus/' . $menu->id . '/edit') . '" style="margin-left: 8px;" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span> Edit</a>';
     }
     return $response;
 }