How to Check Running Laravel App Environment - Techvblogs

How to Check Running Laravel App Environment

Discover how to check running Laravel app environment effortlessly to manage configurations and optimize your app.


Smit Pipaliya - Author - Techvblogs
Smit Pipaliya
 

2 days ago

TechvBlogs - Google News

In this article, We'll talk about the demonstration of the Laravel check app environment. You will learn how to check the application environment in Laravel with several different examples. This article provides many simple examples of checking the environment in which a laravel application is running.

For example, you want to check your Laravel application running in a staging or production environment. So there are many ways to check 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.

How to Check Running Laravel App Environment

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'])) {
            return "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'])) {
            return "This is a production app.";
        }
  
    }
}

Example 3:

@if(App::environment('production'))
     <h1>Production Environment</h1>
@endif

Example 4:

@production
     <h1>Production Environment</h1>
@endproduction

Example 5:

@env('local', 'staging')
    <h1>Local or Staging Environment</h1>
@endenv

Thank you for reading this article.

Read Also: How to Define Constant Variables in Laravel

Comments (0)

Comment


Note: All Input Fields are required.