Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Norgul's avatar

Laravel route/method from URL

Is there a way (if not, it would really be helpful in my opinion) for you to provide any URL in your application, and get back the route which will be ultimately called by that URL (or route stack)...maybe even artisan route extension

For example:

php artisan route:list --url=http://myapp.com/help

and get feedback like

URI                             Controller
something/else/help         MyController@getHelp
route/to/here               IntermediateController@getSomething
middleware/something        MyMiddleware@forward
0 likes
2 replies
jdunsmore's avatar

url()->current();

This will give the current URL - but after reading your post several times I'm not sure if your looking for this or if you're looking for

// Everything
$request->fullUrl()

// path of the URL 
$request->path()

// protocol and domain part of the URL
$request->root()

Note - this will ofcourse require Request $request

Norgul's avatar

It is not a problem to get and parse the route I'm on. I am looking for a way to see where the route bounced off.

To give you an exact problem:

Route::get('{slug}', 'StaticPageController@getBySlug')->name('static.slug');

I have this route on the bottom of my routes, and it should be hit whenever an inexistent route is provided. However, when I use myapp.com/qwerty I get the same response as if I entered only myapp.com. Same goes for myapp.com/ifheruifnjfeibfgfgr

Now I'd like to check out why doesn't my slug route get hit. Something is preventing my request from getting to the slug route, and I'd like to trace it by seeing methods it passes through in the process so that I can see where it gets redirected back to the home route which shouldn't happen

Please or to participate in this conversation.