Search code examples
phplaravel-5

Get route path from name in Laravel 5.1


Well I know that route('some.route.name') returns the url for a route based on its name. Is there any way to get a path instead of the url?

I can subtract(or better say str_replace) route('my.website.root.route.name') from it, but I was just wondering if there was a way to do it in a straight forward fashion.

Thanks =)


Solution

  • You can use controller to make links .. and you can use in view with {{ }}

    on controller.. add like,

     public function index() {
        $weburl = asset('http://www.google.com/sample/pic/');
        $myurl = asset('/mysite/data/sample/');
    
        $data= array(
                        'weburl' => $weburl,
                        'myurl' => $myurl,
                    );
    
        return View('index', $data);
    }
    

    then you can call this links on view using double curly brackets

    {{ $weburl }} or {{ $myurl }}
    

    Guess this way is easier to use..