protected function setSelectedNavigation()
    {
        $url = $this->getCurrentUrl();
        $sections = $this->getCurrentUrlSections();

        // laravel removes last /
        if ($url === false) {
            // dahboard (substring from the /, laravel removes last /)
            $nav = NavigationAdmin::whereSlug('/')->get()->last();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $nav = NavigationAdmin::where('url', '=', $url)
                ->orderBy('is_hidden', 'DESC')//->orderBy('url_parent_id')
                ->orderBy('list_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$nav && strlen($url) > 2) {
            // keep cutting off from url until we find him in the db
            foreach ($sections as $key => $slug) {
                $url = substr($url, 0, strripos($url, '/'));

                // find nav with url - get last (parent can have same url)
                $nav = NavigationAdmin::whereUrl($url)->get()->last();
                if ($nav) {
                    break;
                }
            }
        }

        // development testing
        if (config('app.env') == 'local' && !$nav) {
            //$nav = NavigationAdmin::find(1);
            dump($url);
            dd('Whoops. Navigation not found - please see if url is in database (navigation_admin)');
            //return false;
        }

        $this->selectedNavigation = $nav;

        // get all navigations -> ON parent_id
        $this->parentNavs = $nav->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentNavs = $nav->getUrlParentsAndYou();

        // name of resource - used on page to, eg, Add new 'resource', enter title of 'resource'
        $this->resource = str_singular($nav->title); // TODO: - maybe add a 'resource' field on the table

        $mode = $this->checkIfReservedWordInUrl();

        $this->selectedNavigation->mode = $mode == false ? 'index' : $mode;

        return $this->selectedNavigation;
    }
protected function setSelectedNavigation()
    {
        $url = $this->getCurrentUrl();
        $sections = $this->getCurrentUrlSections();

        // laravel removes last /
        if ($url === false) {
            // dahboard (substring from the /, laravel removes last /)
            $nav = NavigationAdmin::whereSlug('/')->get()->last();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $nav = NavigationAdmin::where('url', '=', $url)
                ->orderBy('is_hidden', 'DESC')//->orderBy('url_parent_id')
                ->orderBy('list_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$nav && strlen($url) > 2) {
            // keep cutting off from url until we find him in the db
            foreach ($sections as $key => $slug) {
                $url = substr($url, 0, strripos($url, '/'));

                // find nav with url - get last (parent can have same url)
                $nav = NavigationAdmin::whereUrl($url)->get()->last();
                if ($nav) {
                    break;
                }
            }
        }

        // development testing
        if (config('app.env') == 'local' && !$nav) {
            //$nav = NavigationAdmin::find(1);
            dump($url);
            dd('Whoops. Navigation not found - please see if url is in database (navigation_admin)');
            //return false;
        }

        $this->selectedNavigation = $nav;

        // get all navigations -> ON parent_id
        $this->parentNavs = $nav->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentNavs = $nav->getUrlParentsAndYou();

        // name of resource - used on page to, eg, Add new 'resource', enter title of 'resource'
        $this->resource = str_singular($nav->title); // TODO: - maybe add a 'resource' field on the table

        $mode = $this->checkIfReservedWordInUrl();

        $this->selectedNavigation->mode = $mode == false ? 'index' : $mode;

        return $this->selectedNavigation;
    }
protected function setSelectedNavigation ( ) { $ url = $ this -> getCurrentUrl ( ) ; $ sections = $ this -> getCurrentUrlSections ( ) ; // laravel removes last / if ( $ url === false ) { // dahboard (substring from the /, laravel removes last /) $ nav = NavigationAdmin :: whereSlug ( '/' ) -> get ( ) -> last ( ) ; } else { // find nav with url - get last (parent can have same url) $ nav = NavigationAdmin :: where ( 'url' , '=' , $ url ) -> orderBy ( 'is_hidden' , 'DESC' ) //->orderBy('url_parent_id') -> orderBy ( 'list_order' ) -> get ( ) -> last ( ) ; } // we assume some params / reserved word is at the end if ( ! $ nav && strlen ( $ url ) > 2 ) { // keep cutting off from url until we find him in the db foreach ( $ sections as $ key => $ slug ) { $ url = substr ( $ url , 0 , strripos ( $ url , '/' ) ) ; // find nav with url - get last (parent can have same url) $ nav = NavigationAdmin :: whereUrl ( $ url ) -> get ( ) -> last ( ) ; if ( $ nav ) { break ; } } } // development testing if ( config ( 'app.env' ) == 'local' && ! $ nav ) { //$nav = NavigationAdmin::find(1); dump ( $ url ) ; dd ( 'Whoops. Navigation not found - please see if url is in database (navigation_admin)' ) ; //return false; } $ this -> selectedNavigation = $ nav ; // get all navigations -> ON parent_id $ this -> parentNavs = $ nav -> getParentsAndYou ( ) ; // get all navigations -> ON url_parent_id $ this -> urlParentNavs = $ nav -> getUrlParentsAndYou ( ) ; // name of resource - used on page to, eg, Add new 'resource', enter title of 'resource' $ this -> resource = str_singular ( $ nav -> title ) ; // TODO: - maybe add a 'resource' field on the table $ mode = $ this -> checkIfReservedWordInUrl ( ) ; $ this -> selectedNavigation -> mode = $ mode == false ? 'index' : $ mode ; return $ this -> selectedNavigation ; }
Set the Current Navigation
Find the navigations parents and url parents

@return bool
Set the Current Navigation Find the navigations parents and url parents