<?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();