
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
- Use of undefined constant laravel
- Page loader in laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- Save or update pivot table data with additional column in Laravel
- Shorter syntax for whereHas with call back function in laravel
- Create record with unique slug in laravel
- How to check query string exists or not in laravel blade
- How to display order by null last in laravel
- Where to use whereNotNull eloquent in laravel
- How to get the id of last record from collection object in laravel view
- Call to a member function update() on null
- How to get records in random order in laravel
- Property [user] does not exist on this collection instance
- Return redirect laravel not working
- How to get query string value in laravel
- Laravel save object to database
- How to get random string in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- How to get last month records in Laravel
- Laravel csrf token mismatch for ajax POST Request
- Laravel get all records with pagination
- How to get last year records count with month wise in Laravel
- Extract only time from datetime in laravel
- Submit form without CSRF token in Laravel