1

How I can create automatically record daily with laravel task scheduling without running artisan command. In my case I just want when the date is 28-02-2020 create record in db, when date is 29-02-2020 create another record and etc...

JohnSmith
  • 129
  • 1
  • 8

1 Answers1

1

Just check Laravel docs on Task Scheduling. First add this cron entry:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Then, You may define all of your scheduled tasks in the schedule method of the App\Console\Kernel class:

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        DB::table('your_table')->insert([
            'first_column' => 'first_value',
            // List other columns
        ]);
    })->daily();
}
Hafez Divandari
  • 6,148
  • 4
  • 32
  • 54
  • Thank you. But I am on shared hosting? Is it will be automatically without run commands? – JohnSmith Feb 28 '20 at 12:58
  • @JohnSmith No it won't run automatically without a cron job, most of the shared hosts have a panel that you can manually add cron jobs (e.g cPanel) https://hostadvice.com/how-to/how-to-setup-cron-jobs-on-cpanel/ – Hafez Divandari Feb 28 '20 at 13:02
  • Okey. How to configure laravel task schedukling (cron job) on Windows? – JohnSmith Feb 28 '20 at 13:06
  • @JohnSmith check [this](https://stackoverflow.com/a/22772792/3477084) and [this](https://stackoverflow.com/a/132975/3477084) answers. – Hafez Divandari Feb 28 '20 at 13:11