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
- Return redirect laravel not working
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Eager loading dynamically in laravel
- How to validate form input data in laravel
- Get Array of IDs from Eloquent Collection
- How to send email in laravel
- How to randomly get the user id from users table in laravel
- Display data in table using foreach in Laravel
- Credit card validation in laravel
- How to remove P tag from CkEditor in Laravel?
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- How to get file extension from input type file in laravel
- Permission denied error while creating storage link in Laravel
- How to get all posts which contains comments in laravel
- Return view from route Laravel
- Get laravel version
- Drop foreign key column in Laravel using migration
- Multiple Level eager loading in Laravel
- Trying to get property 'title' of non-object
- How to customize or Change validation error messages
- Target class [admin] does not exist.
- How to pass two variables in HREF in laravel
- How to pass variable from controller to model in Laravel
- How to change default timestamp fields name in Laravel
- How to get random string in Laravel