Laravel / Lumen Task Scheduling or Set Cron Job

composer require flipbox/Lumen-generator
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
php artisan make:command CleanTable
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class CleanTable 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()
{
//
}
}
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

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

/**
* 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()
{
// Clean the log table
DB::table('log_table')->delete();
}
}
Commands\CleanTable::class
$schedule->command('clean:table') ->hourly();
php artisan schedule:list
php artisan schedule:run
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CodingHub

CodingHub

Coding Hub — Learn & Build Your Career