10-Apr-2023
.
Admin
Hi Dev,
Today, I would like to show you how to get HTTP hostname in laravel 8. This article will give you simple example of get HTTP host name. let’s discuss about laravel 8 in how to get HTTP hostname. This tutorial will give you simple example of laravel 8 HTTP host name. Let's see bellow example laravel 8 get HTTPhost name.
A very few days ago i was trying to get hostname in my laravel 9 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().
Download Laravel
Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.
composer create-project laravel/laravel example-app
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();
dd($host);
}
It will help you...
#Laravel 9