xxxxxxxxxx
Example 1: current() with Helper
$currentURL = url()->current();
dd($currentURL);
Example 2: full() with Helper(with query string parameters)
$currentURL = url()->full();
dd($currentURL);
Example 3: current() with Facade
$currentURL = URL::current();
dd($currentURL);
Example 4: full() with Facade(with query string parameters)
$currentURL = URL::full();
dd($currentURL);
Example 5: using Request
$currentURL = Request::url();
dd($currentURL);
Get Previous URL in Laravel:
$url = url()->previous();
dd($url);
Get Current Route in Laravel:
$route = Route::current()->getName();
dd($route);
xxxxxxxxxx
// 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();
xxxxxxxxxx
// Get the base URL.
echo url('');
// Get the app URL from configuration which we set in .env file.
echo config('app.url');
xxxxxxxxxx
// Full URL with query string
print $request->fullUrl(); // http://127.0.0.1:8000/sometext?city=hyd
// Get the path part of the URL
print $request->path(); // sometext
// Root (protocol and domain) part of the URL)
print $request->root(); //http://127.0.0.1:8000
//Get the full URL for the previous request
print url()->previous();
//tested on Laravel 5.6
//OR
use Illuminate\Support\Facades\URL;
print URL::current();
xxxxxxxxxx
//get current url
use Illuminate\Support\Facades\Route;
Route::getFacadeRoot()->current()->uri();
//get current full url
$url = url()->current();
xxxxxxxxxx
$currentURL = URL::current(); PHP.
$url = URL::to("/"); or use $url = url('/'); PHP.
$route = Route::current()->getName(); PHP.
$prefix = Request::route()->getPrefix(); PHP.