Saturday, June 23, 2018

phpMyPassion

How To Get Current Route Name Path in Laravel 5.4 ?



Here I am going to share you problem that most of the laravel beginner found when developed a project with laravel. You can get to know about the solution for the issue 'get current route name path in laravel 5.4' with this article.

Get Current Route Name Path From view (blade template) -

You can get the current route name path from view (blade template) by using below code -

{{ url()->current() }} // It will return route name with url

{{ Request::path() }} // It will return only route name like - route-name

It will return the current active route name path like -

             " http://your-app-url/route-name "

Get Current Route Name Path From Controller/Model -

You can also get the current route name path from controller / model by using below code -

Another option, if you have the "Request $request" object (which you probably do if you used dependency injection in the controller), then you can just do this:

$request->url()


Note that that's the URL without any query (GET) variables. These are also useful depending on what you want:

// Get current route name path
url()->current();
// Full URL, with query string $request->fullUrl() // Just the path part of the URL $request->path() // Just the root (protocol and domain) part of the URL) $request->root()

Above methods also work from the "Request::" facade.


About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a hug of information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :