Posts Learn Components Snippets Categories Tags Tools About

How to get base URL in Laravel

Learn how to get the base URL in Laravel application using the helper function

Created on Oct 18, 2021


In this snippet, you will learn how to get the base URL in the Laravel application. 

Using getSchemeAndHttpHost method


// get url using "getSchemeAndHttpHost" 

Using url() Helper Method

You can also use the "url()" helper function method

// get the base url using the "url" helper

Using config Helper method

You can make use of the "config()" helper method as well.

// get the url from the "app.url"

Other: Accessing Current URL

There are other helper methods as well to get the "current" URL of a page and you can write your code as follows
// Get the current page URL without the query string
echo url()->current();

// Get the current page URL including the query string
echo url()->full();

// Get the full page URL for the previous page
echo url()->previous();

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to get base URL in Laravel