diff --git a/Concerns/ParsesSearchPath.php b/Concerns/ParsesSearchPath.php new file mode 100644 index 000000000..437ff2b26 --- /dev/null +++ b/Concerns/ParsesSearchPath.php @@ -0,0 +1,29 @@ +parseSearchPath( - $this->connection->getConfig('search_path') ?: 'public' + $this->connection->getConfig('search_path') ?: $this->connection->getConfig('schema') ?: 'public' ); $parts = explode('.', $reference); @@ -215,9 +221,7 @@ protected function parseSchemaAndTable($reference) // We will use the default schema unless the schema has been specified in the // query. If the schema has been specified in the query then we can use it // instead of a default schema configured in the connection search path. - $schema = $searchPath[0] === '$user' - ? $this->connection->getConfig('username') - : $searchPath[0]; + $schema = $searchPath[0]; if (count($parts) === 2) { $schema = $parts[0]; @@ -228,24 +232,16 @@ protected function parseSchemaAndTable($reference) } /** - * Parse the "search_path" value into an array. + * Parse the "search_path" configuration value into an array. * - * @param string|array $searchPath + * @param string|array|null $searchPath * @return array */ protected function parseSearchPath($searchPath) { - if (is_string($searchPath)) { - preg_match_all('/[a-zA-z0-9$]{1,}/i', $searchPath, $matches); - - $searchPath = $matches[0]; - } - - $searchPath ??= []; + $searchPath = $this->baseParseSearchPath($searchPath); array_walk($searchPath, function (&$schema) { - $schema = trim($schema, '\'"'); - $schema = $schema === '$user' ? $this->connection->getConfig('username') : $schema;