
How to check Laravel application running Environment?
There are different ways to check the laravel application running environment. We will discuss them one by one.
Sometimes, we have to check the application environment and based on that we have to do some task in our app. So there are some methods available in Laravel to determine the current environment of Laravel application to solve the problem.
You can call the environment method on app facade and get the current working environment $environment = App::environment();
.
-
Check the running environment in the controller using Laravel
In your controller, you can use app facade to get the current working environment in Laravel. You have to import App facade in your controller file and use the environment() method to get the current running environment.
app\Http\Controllers\HomeController.php
if (App::environment('local')) { // The environment is local }
if (App::environment(['local', 'staging'])) { // The environment is either local OR staging... }
-
Get the current working environment in Laravel blade
resources\views\home.blade.php
@if(App::environment('local')) <p> in Local environment </p> @endif
You have to place code in your blade file and pass the value to environment method which is exists in .env file (APP_ENV=local) or configuration file (config/app.php) 'env' => env('APP_ENV', 'local'),.
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
- Get domain name in laravel
- Save or update pivot table data with additional column in Laravel
- How to get records in random order in laravel
- Route not defined in Laravel
- Delete records with relationship in laravel
- Display data in table using foreach in Laravel
- Display first n record from collection in laravel view
- How to disable timestamps in laravel
- How to create project_user pivot table in laravel
- Laravel hasmany select not working
- Symlink(): No such file or directory
- Get 30 days older records from table in laravel
- Update existing pivot table data in laravel
- Page loader in laravel
- Laravel get single row by id
- Composer\Exception\NoSslException
- Touch parent updated_at in Laravel
- Print last executed query in laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Create model with migration and seeder
- Illuminate\Database\QueryException could not find driver
- Delete all related comments on deleting a post in Laravel
- How to use more than one query scope in Laravel
- Create record with unique slug in laravel
- How to decrypt laravel password