这里是按照每天去创建一个表代码稍显捡漏

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redis;
use Carbon\Carbon;
use Illuminate\Support\Facades\Schema;
public function index(){
    $tables = DB::select('SHOW TABLES');
    $object =  json_decode( json_encode( $tables),true);
    $names = array();
    foreach($object as $k => $v){
        $names[] = $v['Tables_in_shop'];
    }
    $time = 'sp_ad'.Carbon::now()->toDateString();
    $isin = in_array($time,$names);
    if($isin){
        echo '已存在';
    }else{
        echo "不存在";
        Schema::create($time, function ($table) {
            $table->increments('id');
            $table->char('adname',45);
        });
    }
    DB::table($time)->insert(
        [
            'adname'=>'daze',
        ]
    );
}

laravel 自动分表

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-24
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-11-26
相关资源
相似解决方案