![Logo loader icon](https://w3codegenerator.com/img/logo-f2.png)
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
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Method Illuminate\Http\Request::validated does not exist
- Update existing pivot table data in laravel
- How to create belongstomany relation using custom name on custom pivot table
- Insert data with form validation using ajax in laravel
- How to get laravel errors folder in views directory in laravel
- Class 'App\Providers\Auth' not found
- How to decrypt laravel password
- Get only 10 records from table in laravel
- How to change default timestamp fields name in Laravel
- Laravel create default admin user
- Shorter syntax for whereHas with call back function in laravel
- Rendering HTML from database table to view in Laravel
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Route [password.request] not defined
- How to customize or Change validation error messages
- Redirect to previous page or url in laravel
- Get latest record by created at in Laravel
- Laravel hasmany select not working
- Skip first n record and display rest records in laravel view
- Drop foreign key column in Laravel using migration
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- How to get route name on visit URL in laravel
- Get the products list ordered by a user
- How to call controller function from view in Laravel