
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
- How to get session in blade Laravel ?
- Attempt to read property "avatar" on null in Laravel
- Comment .env file in laravel
- How to display pivot table column value in laravel
- Get previous date data in laravel
- How to create projects method with belongstomany relationship in user model
- How to remove P tag from CkEditor in Laravel?
- How to use or operator in laravel
- How to validate website url in laravel using validaiton
- How to create new user without form submission in laravel
- How to upload multiple images after preview in laravel using cropper js
- How to check duplicate entry in laravel
- Permanently delete a record in laravel
- Print last executed query in laravel
- Call to a member function update() on null
- How to prevent host header attack in Laravel
- Get content from web URL in laravel
- Json encode method in laravel
- Laravel pagination links with query string
- How to get last month records in Laravel
- Create project table with model and migration
- Laravel recursive function in controller
- How to add unique records in pivot columns of Laravel pivot table
- How to get route method name in Laravel
- Laravel create table migration with model