rockstardev
rockstardev

Reputation: 13537

Get current URL in Laravel without parsing?

It's quite easy to get the current URL:

Request::url()

This would return something like:

http://localhost/some/or/other/path

However, if I want an easy way to get only:

some/or/other/path

What would I do? Is there a way to do this without parse_url? I.e. Does Laravel have an inherent built-in way to do this?

Upvotes: 1

Views: 2528

Answers (3)

Dmitry Nevzorov
Dmitry Nevzorov

Reputation: 615

An alternative way is to use the controller action parameter $request:

$request->path();
//or global helpers
request()->path();

The functionality is available now (docs) and at least since Laravel 5.2

Upvotes: 0

Hayk Aghabekyan
Hayk Aghabekyan

Reputation: 1087

In my codes I am using code below (Laravel version 4)

Request::url();

Upvotes: 1

peterm
peterm

Reputation: 92845

How about Request::path()?

$uri = Request::path();

Upvotes: 6

Related Questions