love_php/app/Models/SplitModel.php

36 lines
907 B
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SplitModel extends Model
{
protected $suffix = null;
//设置表后缀
public function setSuffix($suffix)
{
$this->suffix = $suffix;
if ($suffix !== null) {
$this->table = $this->getTable().'_'.$suffix;
}
}
//设置表后缀-静态方法
public static function suffix($suffix)
{
$instance = new static;
$instance->setSuffix($suffix);
return $instance->newQuery();
}
//创建新的后缀名的模型实例并返回
// public function newInstance($attributes = [], $exists = false)
// { \Illuminate\Support\Facades\Log::info('newInstance');
// $model = parent::newInstance($attributes, $exists); // TODO: Change the autogenerated stub
// $model->setSuffix($this->suffix);
// return $model;
// }
}