در حال بارگذاری ...

Scheduling in Laravel 110:00

As we stated in the last episode, there is no kernel, HTTP or console in the Laravel 11 skeleton, but we use the console kernel to schedule tasks. For example, in this Laravel 10 application, in schedule, I'm making sure that every day we prune old models from this project. How would we do that in Laravel 11? We can do that using the brand new schedule facade, and the best place to put all of this code is in console.php in your roots file. It really does streamline and simplify the whole process. So here we have the command for php artisan inspire, but let's say we wanted to add a schedule, well I'll make use of the new schedule facade, and we'll say that we

Adding a Daily Prune0:44

So here we have the command for php artisan inspire, but let's say we wanted to add a schedule, well I'll make use of the new Schedule facade, and we'll say that we want to call model prune daily, and that's it. If we go to the terminal now and run php artisan schedule:list, you can see php artisan model prune is in fact on the schedule in 8 hours, and here is the cron setup. Note too though that php artisan inspire is also in this list. How is that on the cron? Well take another look at the command declaration. Here is php artisan inspire, however at the end here we chain on this hourly method. You can add this to any command to automatically schedule it right in place rather than having

Inline Command Scheduling1:23

Here is php artisan inspire, however at the end here we chain on this hourly method. You can add this to any command to automatically schedule it right in place rather than having to use the schedule facade separately underneath. Of course you could change this to daily, you could change it to weekly, or on a particular day of the week, or a day at the weekend. So don't worry, all of the powerful scheduling methods that Laravel has always had are still there, you just access them through the schedule facade, or as one of the helper methods when using artisan::command.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟