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
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply