[10.x] Introduce requireEnv
helper
#48261
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It sometimes happens that we want to ensure that some environment variables are set, without relying on their default value, in case they are not found.
This is very much the case when working as a team with new joiners when setting up their Laravel project locally.
I believe it is valuable to have a way to defined if a given environment variable needs to be explicitly set.
This pull-request introduces the
requireEnv()
helper and the\Illuminate\Support\Env::getRequired()
method for this purpose.They don't accept any default value, and an exception is thrown if the environment variable is not found.
Note:
The helper could also be named
requiredEnv()
(with ad
), I don't have a strong opinion about this.