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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay