Skip to content

Commit 7c0e6ad

Browse files
[11.x] Adds withSchedule to bootstrap/app.php file (#50755)
* Adds `withSchedule` * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent bf02fde commit 7c0e6ad

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Illuminate/Foundation/Configuration/ApplicationBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Illuminate\Foundation\Configuration;
44

55
use Closure;
6+
use Illuminate\Console\Application as Artisan;
7+
use Illuminate\Console\Scheduling\Schedule;
68
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
79
use Illuminate\Contracts\Http\Kernel as HttpKernel;
810
use Illuminate\Foundation\Application;
@@ -280,6 +282,21 @@ protected function withCommandRouting(array $paths)
280282
});
281283
}
282284

285+
/**
286+
* Register the scheduled tasks for the application.
287+
*
288+
* @param callable(Schedule $schedule): void $callback
289+
* @return $this
290+
*/
291+
public function withSchedule(callable $callback)
292+
{
293+
$this->app->afterResolving(ConsoleKernel::class, function (ConsoleKernel $kernel) use ($callback) {
294+
Artisan::starting(fn () => $callback($this->app->make(Schedule::class)));
295+
});
296+
297+
return $this;
298+
}
299+
283300
/**
284301
* Register and configure the application's exception handler.
285302
*

0 commit comments

Comments
 (0)