Skip to content

Commit

Permalink
feat(stFrom): Add alias parameter for stFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
saibotk committed Dec 27, 2023
1 parent cfc9ecf commit 6fb4dbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

## [1.4.0](https://github.com/clickbar/laravel-magellan/tree/1.4.0) - 2023-07-02

### Improved
Expand Down
11 changes: 9 additions & 2 deletions src/Database/Builder/BuilderMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
}

Expand Down

0 comments on commit 6fb4dbb

Please sign in to comment.