Skip to content

[13.x] Allow enums in environment checks - #61730

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
Taldres:feature/environment-enums
Sep 25, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
Taldres:feature/environment-enums

Conversation

@Taldres

@Taldres Taldres commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Apps that model their environments as an enum can already use it with the #[Bind] attribute, but not with the framework's other environment checks:

enum Environment: string
{
    case Local = 'local';
    case Staging = 'staging';
    case Production = 'production';
}

App::environment(Environment::Production);
// Error: Object of class Environment could not be converted to string

Schedule::command('reports:send')->daily()->environments(Environment::Production);
// No error, but the task never runs

The scheduler case is the more surprising one. environments() stores the enum as-is, and runsInEnvironment() compares it against the current environment string, so the task is silently skipped on every environment.

This PR passes the given values through enum_value(), the same way #[Bind] already handles its environments argument. Backed enums (and unit enums, by case name) now work with:

  • App::environment() / app()->environment(), including @env(...) in Blade, which compiles down to it
  • environments() on scheduled events and on Schedule::environments(...)->group(...)

String values behave exactly as before, wildcard patterns included, and signatures and return types are unchanged. The scheduler stores the normalized strings, so anything reading $event->environments, like schedule:list --json, still gets plain strings.

Tests cover both the application and the scheduler.

App::environment() threw when given an enum, and scheduled events
limited to enum environments silently never ran. Normalize the values
with enum_value(), as the #[Bind] attribute already does.
@Taldres
Taldres marked this pull request as draft September 25, 2026 12:29
@Taldres
Taldres marked this pull request as ready for review September 25, 2026 12:58
@taylorotwell
taylorotwell merged commit 4f8acd7 into laravel:13.x Sep 25, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants