Get current url path



How many examples I have not seen, all are essentially the same, and perform the same thing. Let’s take a look at one of them.

Route::current()->uri()

We have url https://example.com/test and we get test, and in all examples the same

But how to make sure that we get not just test but with a slash /test?

Answer

You can get it with this piece of code:

request()->getPathInfo();

Laravel Illuminate/Http/Request extends Symfony Request class which contains getPathInfo method.

Docs: https://symfony.com/doc/current/components/http_foundation.html#identifying-a-request

Definition of that method you can find here.



Source: stackoverflow