How to call env variable in Laravel controller
How to call env variable in Laravel controller
In this session, we are going to try to solve the "How to call env variable in Laravel controller" puzzle by using the computer language.
I have some env variable in my .env file. I want to get the value of these env variable in my Laravel controller. Is there any way to call the env variable to controller.-
Get the env variable value in controller and view blade file
env('APP_URL');
//Output
http://localhost:8000Demo code:
Route::get('/get-env', function(){ echo env('APP_URL'); });
Output may be different in your case.
You can use above code snippet to get the value of env variable and you can call it in your controller and blade (view) file.
-
config('app.url');
http://localhost:8000
This code snippet will return the app URL. Which exists in
config/app.php
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
- Validation for multiple forms on same page in laravel
- After image selected get validation error in laravel
- How to display validation error in laravel
- How to get list of all views file in laravel
- How to automatically update the timestamp of parent model in Laravel
- Use withCount() to Calculate Child Relationship Records
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- Seed database using SQL file in Laravel
- Call to a member function pluck() on array
- SQLSTATE[42000]: Syntax error or access violation: 1055
- The use statement with non-compound name 'DB' has no effect
- Ajax GET request in laravel
- How to display serial number in Laravel?
- How to create projects method with belongstomany relationship in user model
- How to pass data to partial view file in laravel
- Laravel get all records with pagination
- How to use bootstrap pagination in laravel 8
- Shorter syntax for whereHas with call back function in laravel
- How to check if user has created any post or not in laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- Multiple Level eager loading in Laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- How to return a column with different name in Laravel
- How to decrypt laravel password
- How to print form data in laravel