laravel 分表日志功能

1.生成定时任务,自动出案件表

  1. 命令行创建定时任务生成脚本   
    php artisan make:command CreateLog
  2. 脚本CreateLog 的handle   方法生成分表的表名
     if ( ! Schema::hasTable($table_name)) {
                $res = DB::statement("create table {$table_name} like {$old_name}");
                return $res;
            } else {
                info("该表{$table_name}已经存在不必创建");
            }
    View Code

     

  3. 脚本增加到定时任务,每月月底自动生成
     $schedule->command('CreateLog')->lastDayOfMonth('11:00');

 

posted @ 2023-02-13 16:25  夫子张  阅读(39)  评论(0编辑  收藏  举报