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.
@env('staging') <p>You are currently in staging environment</p> @endenv
To check for multiple conditions, you can pass it as an array.
@env(['staging', 'production']) <p>You are currently in staging / production environment</p> @endenv
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> @endif
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> @endif
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> @endif @if (config('app.env') === 'local || config('app.env') === 'production') <p>You are currently in local / production environment</p> @endif
Other Read
Leave a reply