Level 122
Not sure what context you are expecting? A command boots the framework and runs completely isolated from anything else.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, here's what on my mind:
<?php
// app/Http/Commands/TestCommand.php:
class TestCommand extends Command
{
public string $subdomain = 'foobar';
public function handle(Tenant $tenant)
{
$this->info("{$tenant->subdomain()} selected");
}
}
// app/Providers/TenantProvider.php
class TenantProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(Tenant::class, function (Application $app, $parameters) {
if ($app->runningInConsole()) {
$subdomain = $app->***theClassIAmRequestedIn***->subdomain
?? theClassIAmRequestedIn->subdomain->getArguments()[0]
?? null;
return Tenant::for($subdomain);
}
});
}
}
I know I can access request() if it's a web-request, but Commands, Actions, Jobs -- is there a way to get some context about "what's executed right now" when resolving something from a service container?
Please or to participate in this conversation.