DEV Community

Cover image for How to Get Current Full URL in Laravel 11
Saddam Hossain
Saddam Hossain

Posted on

1

How to Get Current Full URL in Laravel 11

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

Read More

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more