
Get domain name in laravel
Get domain name in laravel
Through the use of the programming language, we will work together to solve the "Get domain name in laravel" puzzle in this lesson.
There are lots of method available in laravel to get the domain name. You can get domain name in laravel using getHost() and getHttpHost() method on request() helper.-
Get domain name in laravel using web.php file
$host = request()->getHttpHost();
Output :
w3codegenerator.com
$getHost = request()->getHost();
Output :
w3codegenerator.com
$hostwithHttp = request()->getSchemeAndHttpHost();
Output :
https://w3codegenerator.com
Code Example routes\web.php
Route::get('/get-domain', function(){ $host = request()->getHttpHost(); echo $host ."<br/>"; $getHost = request()->getHost(); echo $getHost ."<br/>"; $hostwithHttp = request()->getSchemeAndHttpHost(); echo $hostwithHttp ."<br/>"; });
Copy/Paste code in your web.php file and it will return the domain name in laravel on visit http://localhost:8000/get-domain . You can use this code snippet in view and as well as controller file.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Session Doesn't Work on Redirect
- How to customize pagination view in laravel
- How to get column names from table in Laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Laravel recursive function in controller
- How to check if user has created any post or not in laravel
- Pagination in laravel
- Laravel change date format
- Print last executed query in laravel
- Laravel create multiple records in Pivot table
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Cannot end a section without first starting one
- How to check data inserted or deleted in pivot after toggle method
- Class 'App\Rules\Hash' not found in Laravel
- How to get session in blade Laravel ?
- Laravel 7 login error message not showing
- How to check find method executed successfully in laravel
- Print query in laravel
- Route group with URI prefix using middleware and route name prefixes
- Ajax GET request in laravel
- Add a subselect based on relationship using withAggregate method
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Rename Pivot Table in Laravel
- How to pass link from controller to view in laravel on ajax call
- How to send ID to another page in Laravel