Snippets - Laravel

Ensure environment key exists in Laravel

|
Anuz Pandey

You can use Laravel's getOrFail method from Env helper class to ensure that the environment key exists in the .env file.

If the environment key APP_LICENCE_KEY is not present in the .env file, a runtime exception will be thrown with the message, "Environment variable APP_LICENCE_KEY has no value."

Keep coding, keep exploring and inspiring. 🐼


  • Tags:
  • laravel
  • env
  • php