(举例)Laravel 怎么分表
举例
<?php
namespace App\Models;
use DB;
use Schema;
use Illuminate\Database\Eloquent\Model;
class Logs extends Model
{
protected $guarded = ['id'];
protected $table;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = 'log_'.date('Y');
if (!Schema::hasTable($this->table))
{
DB::update('create table '.$this->table.' like logs');
}
}
}
- 前提是你有logs这个表,这样才能复制表
使用(举例)
Logs::where('uid','')->first();
本作品采用《CC 协议》,转载必须注明作者和本文链接
:joy:没这样用过 但我简单说个题外话 调用静态方法会走
__construct
?分别后如何聚合查询呢?或者说查所有数据?
没索引