A very few days ago i was trying to get hostname in my laravel 5.7 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...
Do you like below Tutorials ?
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples
- Convert object to array in laravel 7.x and 6.x example