How To Get HTTP Hostname In Laravel 9?
Apr 16, 2022 . Admin
Hi Dev,
In this short tutorial we will cover an how to get HTTP hostname in laravel 9. I explained simply about get HTTP host name. you can understand a concept of laravel 9 in how to get HTTP hostname. we will help you to give example of laravel 9 HTTP host name. So, let's follow few step to create example of laravel 9 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 LaravelLet 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-appExample 1 :
$host = request()->getHttpHost();Example 2 :
$host = request()->getHost();Example 3 :
<?php /** * Write code on Method * * @return response() */ public function yourControllerFun(Request $request) { $host = $request->getHttpHost(); dd($host); }
I hope you found your best...