时间:2021-07-01 10:21:17 帮助过:15人阅读
class singletonInstance
{
protected static $instances = [];
protected static $table = null;
protected static $connection = null;
public function __construct()
{
if(!isset(static::$instances[static::class])){
if(is_null(self::$table) || is_null(self::$connection))
{
throw new \Exception('not defined property');
}
static::$instances[static::class] = DB::connection(self::connection)->table(self::$table);
}
}
public static function getDB()
{
return static::$instances[static::class];
}
}
以上就是laravel連接多個不同數據庫的單例類的详细内容,更多请关注Gxl网其它相关文章!