7

I create a cron job on laravel 5.3 by editing app\Console\Kernel.php like this :

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use DB;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        //
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            $id = 1;
            DB::table('orders')
              ->where('id', $id)
              ->update(['status ' => 2, 'canceled_at' => date("Y-m-d H:i:s")]);
        })->everyMinute();
    }

    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

I tried to check on the table in the database, but it does not update

How can I test my cron job?

samuel toh
  • 6,836
  • 21
  • 71
  • 108

3 Answers3

11

You can follow below steps:

1) You can run php artisan list command in cmd and find your cron.

2) After find your cron, then you can run php artisan yourcron.

You can follow this link for more details about cron job.

Hope this work for you!

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • When I run this : `php artisan yourcron` 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 – samuel toh Jan 10 '17 at 02:35
  • did you add the schedule command on your crontab on the server – Ritesh Ksheersagar Jan 08 '18 at 16:27
  • Maybe instead of `php artisan list` you can do `php artisan schedule:list` which will only show the cron / scheduled jobs – Craig Wayne Aug 17 '23 at 18:55
6

Go to the project directory and run

php /path/to/artisan schedule:run

More info about that: https://laravel.com/docs/5.3/scheduling

Orbán Zoltán
  • 394
  • 3
  • 12
0

hey you can create log file too at the time of defining cron. as i ahve created mine...

* * * * * php /var/www/html/sharep/artisan ElasticSearch:ElasticSearchData >> /var/www/html/sharep.log 2>&1

this cron run after 1 minute. and the logs saves in .log file as mention above.

Priyank lohan
  • 483
  • 1
  • 6
  • 17