diff --git a/src/Query/Concerns/CompilesJoins.php b/src/Query/Concerns/CompilesJoins.php index ae133e8..56b4ae7 100644 --- a/src/Query/Concerns/CompilesJoins.php +++ b/src/Query/Concerns/CompilesJoins.php @@ -20,13 +20,15 @@ public function extractTableAndAlias(Builder $query, $join): array { if ($join->table instanceof Expression) { $tableParts = []; - preg_match("/(^.*) as (.*?)$/", (string) $join->table->getValue($query->grammar), $tableParts); - $table = $tableParts[1]; - $alias = $tableParts[2]; - $query->registerTableAlias($join->table, $alias); + if (preg_match("/(^.*) as (.*?)$/", (string) $join->table->getValue($query->grammar), $tableParts)) { + $table = $tableParts[1]; + $alias = $tableParts[2]; - return [$table, $alias]; + $query->registerTableAlias($join->table, $alias); + + return [$table, $alias]; + } } $table = (string) $this->wrapTable($join->table); diff --git a/src/Query/Concerns/HandlesAliases.php b/src/Query/Concerns/HandlesAliases.php index 5a0eee8..4c2357c 100644 --- a/src/Query/Concerns/HandlesAliases.php +++ b/src/Query/Concerns/HandlesAliases.php @@ -182,12 +182,13 @@ public function registerTableAlias(string|Expression $table, string $alias = nul } /** @phpstan-ignore-next-line */ - if ($alias == null && stripos($table, ' as ') !== false) { + if ($alias == null && is_string($table) && stripos($table, ' as ') !== false) { $tableParts = []; - /** @phpstan-ignore-next-line */ - preg_match("/(^.*) as (.*?)$/", $table, $tableParts); - $table = $tableParts[1]; - $alias = $tableParts[2]; + + if (preg_match("/(^.*) as (.*?)$/", $table, $tableParts)) { + $table = $tableParts[1]; + $alias = $tableParts[2]; + } } if ($alias == null) {