diff --git a/CHANGELOG.md b/CHANGELOG.md index c85af9f..c3ff3d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added +- Added `as` parameter for `stFrom` function + ### Fixed - Fixed `ST_PROJECT` function not being migrated to the GeometryType enum. diff --git a/src/Database/Builder/BuilderMacros.php b/src/Database/Builder/BuilderMacros.php index f896454..61712c5 100644 --- a/src/Database/Builder/BuilderMacros.php +++ b/src/Database/Builder/BuilderMacros.php @@ -17,6 +17,7 @@ use Clickbar\Magellan\Database\MagellanExpressions\MagellanStringExpression; use Closure; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\Query\Builder; /** * @mixin \Illuminate\Database\Query\Builder @@ -135,8 +136,14 @@ public function stFrom() * @param \Clickbar\Magellan\Database\MagellanExpressions\MagellanSetExpression $magellanExpression * @return static */ - return function (MagellanSetExpression $magellanExpression) { - return $this->from($magellanExpression->invoke($this, 'from')); + return function (MagellanSetExpression $magellanExpression, string $as = null) { + // NOTE: the `as` field has to be included in the DB expression instead of using the `from` method with the + // `as` parameter, because the latter will try to use the expression in a string concatenation with `as`. + /** @var Builder $this */ + // @phpstan-ignore-next-line Laravel did not type the property correctly + $this->from = $magellanExpression->invoke($this, 'from', $as); + + return $this; }; }