How To Get HTTP Hostname In Laravel 8
Hi Dev,
A very few days ago i was trying to get hostname in my laravel 8 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();
dd($host);
}
I hope you found your best...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial