Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stFrom): Add alias parameter for stFrom #68

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading