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

        // laravel removes last / get home / dashboard
        if ($url === false) {
            $page = Page::where('slug', '/')->get()->first();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $page = Page::where('url', $url)
                ->orderBy('is_hidden', 'DESC')
                ->orderBy('url_parent_id')
                ->orderBy('header_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$page && 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)
                $page = Page::whereUrl($url)->get()->last();
                if ($page) {
                    break;
                }
            }
        }

        // when nothing - fall back to home
        if (!$page) {
            $page = Page::find(1);
            if (config('app.env') == 'local' && !$page) {
                dd('Whoops. Page not found - please see if url is in the pages table');
            }
        }

        // set the selected navigation
        $this->page = $page;

        // get all navigations -> ON parent_id
        $this->parentPages = $page->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentPages = $page->getUrlParentsAndYou();

        $this->page->increment('views');

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

        // laravel removes last / get home / dashboard
        if ($url === false) {
            $page = Page::where('slug', '/')->get()->first();
        }
        else {
            // find nav with url - get last (parent can have same url)
            $page = Page::where('url', $url)
                ->orderBy('is_hidden', 'DESC')
                ->orderBy('url_parent_id')
                ->orderBy('header_order')
                ->get()
                ->last();
        }

        // we assume some params / reserved word is at the end
        if (!$page && 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)
                $page = Page::whereUrl($url)->get()->last();
                if ($page) {
                    break;
                }
            }
        }

        // when nothing - fall back to home
        if (!$page) {
            $page = Page::find(1);
            if (config('app.env') == 'local' && !$page) {
                dd('Whoops. Page not found - please see if url is in the pages table');
            }
        }

        // set the selected navigation
        $this->page = $page;

        // get all navigations -> ON parent_id
        $this->parentPages = $page->getParentsAndYou();

        // get all navigations -> ON url_parent_id
        $this->urlParentPages = $page->getUrlParentsAndYou();

        $this->page->increment('views');

        return $this->page;
    }
protected function findCurrentPage ( ) { $ url = $ this -> getCurrentUrl ( ) ; $ sections = $ this -> getCurrentUrlSections ( ) ; // laravel removes last / get home / dashboard if ( $ url === false ) { $ page = Page :: where ( 'slug' , '/' ) -> get ( ) -> first ( ) ; } else { // find nav with url - get last (parent can have same url) $ page = Page :: where ( 'url' , $ url ) -> orderBy ( 'is_hidden' , 'DESC' ) -> orderBy ( 'url_parent_id' ) -> orderBy ( 'header_order' ) -> get ( ) -> last ( ) ; } // we assume some params / reserved word is at the end if ( ! $ page && 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) $ page = Page :: whereUrl ( $ url ) -> get ( ) -> last ( ) ; if ( $ page ) { break ; } } } // when nothing - fall back to home if ( ! $ page ) { $ page = Page :: find ( 1 ) ; if ( config ( 'app.env' ) == 'local' && ! $ page ) { dd ( 'Whoops. Page not found - please see if url is in the pages table' ) ; } } // set the selected navigation $ this -> page = $ page ; // get all navigations -> ON parent_id $ this -> parentPages = $ page -> getParentsAndYou ( ) ; // get all navigations -> ON url_parent_id $ this -> urlParentPages = $ page -> getUrlParentsAndYou ( ) ; $ this -> page -> increment ( 'views' ) ; return $ this -> page ; }
Get the selected navigation
@return mixed
Get the selected navigation