get current path Laravel 5
19,448
Solution 1
you can use
Request::url()
blade:
{{\Request::url()}} // if is in blade
Solution 2
Laravel has a handy method on the Request
class, coincidentally, called fullUrl()
:
Request::fullUrl();
This is covered in the Laravel documentation: https://laravel.com/docs/master/requests#accessing-the-request
Solution 3
Try this clause:
URL::current();
Or:
$request->url();
Or PHP way:
$_SERVER['REQUEST_URI'];
Comments
-
Jos Koomen almost 2 years
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? -
Jos Koomen about 8 yearsYep, that's working! Thanks
Request::fullUrl();
does also pass theGET request
parameters which i just don't need. In that case the answer of @kscorrales is working for my own situation. -
Jos Koomen about 8 yearsThanks, this was my solution..
use Illuminate\Http\Request;
and you need an instance ofRequest
. the url added by @martin-bean explains how