SoFunction
Updated on 2025-03-06

Summary of the usage method of task scheduling console in Laravel

Applicable scenarios: Analyze data (log)

php artisan make:console Your command class name

Example:

php artisan make:console Check

A file has been generated in the \app\Console\Commands directory

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Check extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'command:name';

  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Command description';

  /**
   * Create a new command instance.
   *
   * @return void
   */
  public function __construct()
  {
    parent::__construct();
  }

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle()
  {
    //
  }
}

You can change $signature to the command name you want

protected $signature = 'check';

At this time, it cannot be called in the console, and it needs to be registered in it.

protected $commands = [
    'App\Console\Commands\Check'
];

You can already use this command in the console

php artisan check

Comment: It doesn't seem to be useful, because php itself can use the CLI command line without using the Laravel framework.