In today’s tutorial, we discuss how to get the HTTP hostname in the Laravel project. The first thing to remember, we have request()
helper that can be used anywhere in the Laravel projects such as blade templates, controllers, models, etc.
So this function is equipped with two methods as shown below to get the HTTP hostname in the Laravel Project.
Example #1
$host = request()->getHttpHost();
Example #2
$host = request()->getHost();
Usage in the real program will be as below:
//app/controllers/PhotoController.php public function index(Request $request) { $hostname = request()->getHttpHost(); dd($hostname ); }
Tested in Laravel 7, 8
Leave a Reply