ItSolutionStuff.com

How to Register Schedule Command in Laravel 11?

By Hardik Savani β€’ September 4, 2024
Laravel

Laravel 11 Schedule Command

Hi, In this post, I will show you how to set up schedule commands in the laravel 11 framework.

The release of Laravel 11 is around the corner, and it is packed with a lot of new features and improvements. Laravel 11 comes with a slimmer application skeleton, introducing a streamlined application structure, per-second rate limiting, health routing, etc.

In Laravel 11, the Kernel.php file for setting up cron job task scheduling command has been removed. We now need to define the cron job in the console.php file. You can see a simple example to create a new command and set it up in Laravel 11.

First, we will create a simple new command using the following command:

php artisan make:command TestJob

Now, you will see the newly created `TestJob.php` file in the Console directory. We will just add some information text to it right now. Let's update the code:

app/Console/Commands/TestJob.php

<?php
  
namespace App\Console\Commands;
  
use Illuminate\Console\Command;
  
class TestJob extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test-job';
  
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';
  
    /**
     * Execute the console command.
     */
    public function handle()
    {
        info('Command run every minute.');
    }
}

Now, you can simply register the created command like the example below:

routes/console.php

<?php
   
use Illuminate\Support\Facades\Schedule;
   
Schedule::command('app:test-job')->everyMinute();

You can set up a cron job in the crontab, and you'll see the output like the following:

[2024-03-08 14:34:53] local.INFO: Command run every minute.  
[2024-03-08 14:35:53] local.INFO: Command run every minute.  
[2024-03-08 14:36:53] local.INFO: Command run every minute. 

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Create Custom Middleware in Laravel 11?

Read Now β†’
β˜…

How to Publish Broadcasting Channels Route File in Laravel 11?

Read Now β†’
β˜…

How to Create and Use Traits in Laravel 11?

Read Now β†’
β˜…

How to use new Dumpable Trait in Laravel 11?

Read Now β†’
β˜…

How to Publish API Route File in Laravel 11?

Read Now β†’
β˜…

How to Create and Use Enum in Laravel 11?

Read Now β†’
β˜…

How to Publish Config Files in Laravel 11?

Read Now β†’
β˜…

How to Create Interface in Laravel 11?

Read Now β†’
β˜…

How to Create Custom Class in Laravel 11?

Read Now β†’
β˜…

How to Publish the lang Folder in Laravel 11?

Read Now β†’
β˜…

What’s New in Laravel 11: New Features and Latest Updates

Read Now β†’
β˜…

How to Install Laravel 11 Application?

Read Now β†’