In this short article, I will show you how to get current full url in laravel 11 application. Laravel 11 provides several methods to get the current URL. You Can Learn Laravel 11 Generate and Read Sitemap XML File Tutorial
We will use the URL facade, url() helper, Route facade, and Request facade to get the current URL. So, let’s see one-by-one example below:
Lets Start How to Get Current Full URL in Laravel 11
Get Current URL in Laravel:
Example 1: current() with Helper
we can use current() function with url() helper to get current url:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* @return \Illuminate\Support\Collection
*/
public function index(Request $request)
{
$currentURL = url()->current();
dd($currentURL);
}
}
Example 2: full() with Helper(with query string parameters)
we can use full() function with url() helper to get current full url with query string parameters:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* @return \Illuminate\Support\Collection
*/
public function index(Request $request)
{
$currentURL = url()->full();
dd($currentURL);
}
}
Top comments (0)