Laravel Checks the Running App Environment
Oct 19, 2022
Hello Friends,
This tutorial will provide an example of laravel checking the running app environment. if you have a question about laravel checking the app environment then I will give a simple example with a solution. This article goes into detail on how to check the current environment in the laravel app. We will use check the application environment laravel. Here, Creating a basic example of checking the app environment laravel.
You can use this example with the versions of laravel 6, laravel 7, laravel 8, and laravel 9.
If you want to check your laravel application running in which environment like staging or production. Then there are several ways to do this. we will use App::environment(), app()->environment(), @production and @env to check app current env. so let's check one by one example as below:
Example 1:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App;
class PostController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index(Request $request)
{
if (App::environment(['local', 'staging'])) {
dd("This is Local or Staging App");
}
}
}
Example 2:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index(Request $request)
{
if (app()->environment(['production'])) {
dd("This is production app.");
}
}
}
Example 3:
@if(App::environment('production'))
{{-- in "production" environment --}}
@endif
Example 4:
@production
{{-- in "production" environment --}}
@endproduction
Example 5:
@env('local', 'staging')
{{-- in "local" or "staging" environment --}}
@endenv
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial