How to get http hostname in Laravel?

A very few days ago i was trying to get hostname in my laravel 5.7 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...

November 16, 2018 | Category : PHPLaravelLaravel 5
Related Posts