How To Get HTTP Hostname In Laravel 8?

Published By: Admin, Published On: Oct 26, 2021, Category: Laravel 8 Laravel

Hi Dev,

A very few days ago i was trying to get hostname in my laravel 8 app. i read whole document of request but i didn't get where to get host name in my controller.

But i found solution for that we can easily get http host name from request object and helper that way you can easily get domain name or sub domain name too. request provide two methods to get hostname as getHttpHost() and getHost().

You can get like as bellow:

Example 1 :
$host = request()->getHttpHost();
Example 2 :
$host = request()->getHost();
Example 3 :
public function yourControllerFun(Request $request) {
    $host = $request->getHttpHost();


I hope you found your best...