0

Would like to build in a simple validation for the value of the APP_ENV parameter in my Laravel application. I want the parameter to be either dev, tst, acc or prd. If it's not one of these, my Laravel application should throw an exception and quit. Something like:

use Illuminate\Support\Facades\App;
use Exception;

$envs = ['dev','tst','acc','prd'];
if(!in_array(App::environment(), $envs)) {
  throw new Exception('Invalid APP_ENV value.');
}

I would like this to be done early in the bootstrapping sequence. I suspect I should put it in a service container and register that in /config/app.php. But this particular thing is still a bit untransparent for me, with my limited experience.

Where should I put my code snippet above, so that it gets executed early in the bootstrapping process?

2
  • 2
    you can add it in AppServiceProvider boot method Commented Dec 29, 2022 at 11:44
  • @JohnLobo Your suggestion works perfectly. Maybe you could answer it as an actual answer? Commented Dec 29, 2022 at 12:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.