diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 7cda4f054413..a8bef27de9d1 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -11,6 +11,7 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Log\Context\Repository; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Date; use Illuminate\Support\Stringable; @@ -197,8 +198,10 @@ protected function start($container) */ protected function execute($container) { + $context = json_encode($container[Repository::class]->dehydrate()); + return Process::fromShellCommandline( - $this->buildCommand(), base_path(), null, null, null + $this->buildCommand(), base_path(), ['__LARAVEL_CONTEXT' => $context], null, null )->run( laravel_cloud() ? fn ($type, $line) => fwrite($type === 'out' ? STDOUT : STDERR, $line) diff --git a/src/Illuminate/Log/Context/ContextServiceProvider.php b/src/Illuminate/Log/Context/ContextServiceProvider.php index 7167518a1b19..dd748321d17f 100644 --- a/src/Illuminate/Log/Context/ContextServiceProvider.php +++ b/src/Illuminate/Log/Context/ContextServiceProvider.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Log\ContextLogProcessor as ContextLogProcessorContract; use Illuminate\Queue\Events\JobProcessing; use Illuminate\Queue\Queue; +use Illuminate\Support\Env; use Illuminate\Support\Facades\Context; use Illuminate\Support\ServiceProvider; @@ -19,6 +20,16 @@ public function register() { $this->app->scoped(Repository::class); + if ($this->app->runningInConsole()) { + $this->app->resolving(Repository::class, function (Repository $repository) { + $context = Env::get('__LARAVEL_CONTEXT'); + + if ($context && $context = json_decode($context, associative: true)) { + $repository->hydrate($context); + } + }); + } + $this->app->bind(ContextLogProcessorContract::class, fn () => new ContextLogProcessor()); }