I using windows
My code on \app\Console\Kernel.php is like this :
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
Commands\CustomCommand::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('custom:command')
->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
My code on \app\Console\Commands\CustomCommand.php is like this :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class CustomCommand extends Command
{
protected $signature = 'custom:command';
protected $description = 'test cron job to update status on table order';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$id = 1;
DB::table('orders')
->where('id', $id)
->update(['status' => 2, 'canceled_at' => date("Y-m-d H:i:s")]);
}
}
I run php artisan list
to see my cron job
After find my cron job (custom:command), then I run my cron job with like this : php artisan custom:command
It's successful update status = 2. After that I change the status manually again become 1, and then I wait one minute, it does not update status again
Is there anyone can help me?
There is no cron job in Windows but if you use Laravel Homestead when you're developing locally this documentation will help you https://laravel.com/docs/5.3/homestead#configuring-cron-schedules
Change your custom command path you have makes like given below
protected $commands = [
Commands\CustomCommand::class,
];
But You want to make like this
protected $commands = [
\App\Console\Commands\CustomCommand::class,
];
Follow this guide on Laravel cron jobs, for scheduling the cron correctly. If you have created a custom artisan command, you will have to define it correctly in your code.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community