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
- Save or update pivot table data with additional column in Laravel
- If no route matched route::fallback in laravel
- Array to string conversion laravel blade
- How to randomly get the user id from users table in laravel
- Split an Eloquent Collection by half in Laravel
- Update last created record in Laravel
- Submit form without CSRF token in Laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Composer create project laravel/laravel example app
- Create user in Laravel using tinker
- How to check find method executed successfully in laravel
- How to get all route list
- How to fetch single row data from database in laravel
- How to create laravel project using composer
- Generate random string lowercase in Laravel
- How to send email in Laravel 11
- Get domain name in laravel
- How to create laravel project using jetstream
- After image selected get validation error in laravel
- Create model with migration and seeder
- How to add unique records in pivot columns of Laravel pivot table
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Insert Comma Separated Values in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- Link storage folder in laravel 8