Executing my function before loading of kernel (Laravel)

89 Views Asked by At

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?

0

There are 0 best solutions below