How to Get HTTP Hostname in Laravel Example

Throughout this Laravel get http hostname tutorial, you will learn How to get the HTTP host with Laravel apps. Using the getHttpHost method or other explained examples you can get http/https host name from request object easily the domain name ( or sub domain ( name as well.

Getting hostname you can use  getHttpHost() and getHost() methods.Let’s start with how to get HTTP hostname (domain) in Laravel. If you get all hostname with http or https then you can use getSchemeAndHttpHost() method.

1. Get the Current Host

Using getHttpHost() method you can get the current domain:

$host = request()->getHttpHost();    // returns 

2. Get the Current Domain

The getHost method is also working the same as getHttpHost() method its returns your domain without http or https;

$host = request()->getHost();  // returns 

3. Get Domain with http/https Protocol

The getSchemeAndHttpHost() returns the domain with http or https protocol.

$host = $request->getSchemeAndHttpHost(); // returns

4. Get Current Url

Using this request url() method you can get the full current URL.

request()->url() // returns // returns

5. Get Host with Function

You can use in these methods same like below code and see in your browser.

public function index(Request $request) {
    $host = $request->getHttpHost(); 

    echo '<pre>'; print_r($host); die; 

6. Get all HTTP header request

Using the headers() method you can see your all headers request.


So, Laravel get http hostname tutorial is over now, I hope you enjoy with this tutorial.

Leave a Comment