How to Check Running Laravel App Environment
In this post we will give you information about How to Check Running Laravel App Environment. Hear we will give you detail about How to Check Running Laravel App Environment And how to use it also give you demo for it if it is necessary.
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 AppHttpControllers;
use IlluminateHttpRequest;
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 AppHttpControllers;
use IlluminateHttpRequest;
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.
Also see: How to Define Constant Variables in Laravel
. .
If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.
Hope this code and post will helped you for implement How to Check Running Laravel App Environment. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs