Posts Learn Components Snippets Categories Tags About

How to check and access environment in Laravel Blade view?

Learn how to check-and-access the environment in Laravel blade view the easy way

Created on Aug 15, 2021


You can access the Laravel environment from the blade views by using several of the provided directive and methods.

Method 1: Using @env Directive
The 1st method to access and check for the current environment is using the @env directive. This method is the most straightforward way you can define it like below.
    <p>You are currently in staging environment</p>

To check for multiple conditions, you can pass it as an array.
@env(['staging', 'production'])
    <p>You are currently in staging / production environment</p>

Method 2: Using env() Helper Method
The second method is to use the env() helper method and you can write it like below
@if (app()->environment('local'))
    <p>You are currently in local environment</p>

When using this method you can pass in multiple conditions such as in "local" and "production" just by passion in the or operator.
@if (app()->environment('local') || app()->environment('production'))
    <p>You are currently in local / production environment</p>

Method 3: Using config() Helper Method
Just like method 2 you can access the config directly using the helper method from the blade template.
@if (config('app.env') === 'local')
    <p>You are currently in local environment</p>

@if (config('app.env') === 'local || config('app.env') === 'production')
    <p>You are currently in local / production environment</p>

Other Read

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets