Home > OS >  Get current url path
Get current url path

Time:10-21

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?

CodePudding user response:

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.

CodePudding user response:

You can try this:

request()->getPathInfo();

You can find the method definition here

CodePudding user response:

You can get url in laravel :


// Get the current URL without the query string...
echo url()->current();

// Get the current URL including the query string...
echo url()->full();

// Get the full URL for the previous request...
echo url()->previous();

  • Related