Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current path Laravel 5

I've tried to find the full path of current route in Laravel 5.x

For this case i've created a method with the following code, but i can't imagine that Laravel does not provide something like this themselves:

 $current = Route::getFacadeRoot()->current();
 $uri = $current->uri();
 foreach ($current->parameters() as $key => $param) {
     $uri = str_replace('{' . $key . '}', $param, $uri);
 }
 return url($uri);

Is there something out of the box in Laravel that i just can't find?

like image 217
Jos Koomen Avatar asked May 06 '16 14:05

Jos Koomen


2 Answers

you can use

Request::url()

blade:

{{\Request::url()}} // if is in blade
like image 142
kscorrales Avatar answered Sep 28 '22 23:09

kscorrales


Try this clause:

URL::current();

Or:

$request->url();

Or PHP way:

$_SERVER['REQUEST_URI'];
like image 35
Alexey Mezenin Avatar answered Sep 29 '22 01:09

Alexey Mezenin