From 6d4388e933e7a96e38d3ce05360d11c65d5dec1a Mon Sep 17 00:00:00 2001 From: jradtilbrook Date: Tue, 25 Nov 2025 11:05:13 +0800 Subject: [PATCH] Allow passing environment variables to scheduled tasks --- Scheduling/Event.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Scheduling/Event.php b/Scheduling/Event.php index 7cda4f0..5aee0b9 100644 --- a/Scheduling/Event.php +++ b/Scheduling/Event.php @@ -90,6 +90,13 @@ class Event */ public $exitCode; + /** + * The additional environment variables for the command. + * + * @var array + */ + public $environment = []; + /** * Create a new event instance. * @@ -198,7 +205,7 @@ protected function start($container) protected function execute($container) { return Process::fromShellCommandline( - $this->buildCommand(), base_path(), null, null, null + $this->buildCommand(), base_path(), $this->environment, null, null )->run( laravel_cloud() ? fn ($type, $line) => fwrite($type === 'out' ? STDOUT : STDERR, $line) @@ -474,6 +481,18 @@ protected function getEmailSubject() return "Scheduled Job Output For [{$this->command}]"; } + /** + * Set the additional environment variables for the command. + * + * @return $this + */ + public function env(array $environment) + { + $this->environment = $environment; + + return $this; + } + /** * Register a callback to ping a given URL before the job runs. *