ItSolutionStuff.com

How to Check Running Laravel App Environment?

By Hardik Savani • April 16, 2024
Laravel

Hey Dev,

In this tutorial, we will go over the demonstration of laravel check app environment. step by step explain how to check app environment in laravel. This article will give you a simple example of check laravel app running environment. if you want to see an example of laravel production env environment then you are in the right place.

You can use this tips in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

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 the 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

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Call External API in Laravel?

Read Now →

How to use Carbon in Laravel Blade or Controller File?

Read Now →

How to Call Controller Function in Blade Laravel?

Read Now →

Laravel Redirect to Route from Controller Example

Read Now →

Laravel Call Function from Same Controller Example

Read Now →

How to Run All Seeders in Laravel?

Read Now →

Laravel US State Seeder Example

Read Now →

How to Run Specific Seeder in Laravel?

Read Now →

Laravel Migration Add Enum Column Example

Read Now →

How to Add Custom env Variables in Laravel?

Read Now →

Laravel Blade Include File If Exists Example

Read Now →

Laravel Deployment on Cloudways with Envoyer

Read Now →

How to Get Current Controller Name in View Laravel?

Read Now →

How to Get Current URL in Laravel?

Read Now →