
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
- Composer create project laravel/laravel example app
- How to pass link from controller to view in laravel on ajax call
- Php artisan make model, factory, migration and controller in single command
- How to validate website url in laravel using validaiton
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- How to avoid duplicate entries in pivot table in Laravel
- Target class [HomeController] does not exist
- How to check record exist or not in relationship table
- How to get list of all views file in laravel
- Update if exist else insert new record in laravel
- How to pass query string to url in laravel
- Get all users except the followings users in overtrue laravel-follow
- Eager loading dynamically in laravel
- Laravel API response format
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Illuminate\Database\QueryException could not find driver
- Laravel pagination links with query string
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to fetch single row data from database in laravel
- Touch parent updated_at in Laravel
- Create project factory and seed data in laravel
- How to insert dynamic value to additional column in pivot table in laravel
- How to get file extension from input type file in laravel
- Get only 10 records from table in laravel
- Laravel create multiple records in Pivot table