How To Get HTTP Hostname In Laravel 8




How To Get HTTP Hostname In Laravel 8

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...

#Laravel 8

#Laravel 7


#Laravel 6