任务调度写在 app/Console/Kernel. PHP 文件 schedule 中,里面默认有一个例子。在 schedule 方法里放入自己的执行的代码。比如这个是每一分钟在 数据库里插入一条数据。

<?php  

namespace App\Console;  
use Illuminate\Console\Scheduling\Schedule;  
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;  
use Illuminate\Support\Facades\DB;  
class Kernel extends ConsoleKernel  

{  

    /**  

     * The Artisan commands provided by your application.  

     *  

     * @var array  

     */  

    protected $commands = [  

        \App\Console\Commands\Inspire::class,  

    ];  

  

    /**  

     * Define the application's command schedule.  

     *  

     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule  

     * @return void  

     */  

    protected function schedule(Schedule $schedule)  

    {  

  

        $schedule->exec(  

            $schedule->call(function () {  

                DB::table('ceshi')->insert(['contents'=>'新的数据']);  

            })->everyMinute()  

        )->daily();  

    }  

}
#添加个任务计划 crontab -e 即可。