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.
Note: Only a member of this blog may post a comment.