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
- Target class [HomeController] does not exist
- How to disable timestamps in laravel
- Get last record from table in laravel
- Sample .htaccess file and index.php file under public directory in laravel
- Comment .env file in laravel
- How to customize pagination view in laravel
- Generate random string lowercase in Laravel
- Class 'App\Rules\Hash' not found in Laravel
- Target class [admin] does not exist.
- Undefined property: stdClass::$title
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Get id of last inserted record in laravel
- How to use bootstrap pagination in laravel 8
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Laravel delete all rows older than 30 days
- Retain selected value of select box in Laravel
- Laravel recursive function in controller
- Docker important commands to run laravel application with docker
- How to change default timestamp fields name in Laravel
- Pass value from controller to model in laravel
- How to decrypt laravel password
- How to get file extension from input type file in laravel
- How to check email is valid or not in Laravel
- How to get id of next record in laravel
- Get products with number of orders in Laravel