Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current URI in Laravel 5.7

I am aware that in the previous versions of Laravel (e.g. 4), one could get the current uri through

Route::current()->uri();

However, this doesn't seem to work in Laravel 5.7 or later. I am wondering how it should be rewritten. Please note that I am accessing the uri in a blade view and hence cannot use non-static methods.

like image 392
Farzan Badakhshan Avatar asked Mar 06 '19 06:03

Farzan Badakhshan


1 Answers

You can get current url in laravel using folling methods.

// 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();

Each of these methods may also be accessed via the URL facade:

use Illuminate\Support\Facades\URL;

echo URL::current();

For more information you can read full documentation here.

like image 119
Jigar Avatar answered Sep 27 '22 21:09

Jigar