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連接多個不同數據庫的單例類的详细内容。
