Skip to content

Commit

Permalink
Merge pull request #123 from clickbar/rename-alias-param
Browse files Browse the repository at this point in the history
[2.x] Rename Aliased.php param 'alias' to 'as'
  • Loading branch information
saibotk authored Jan 3, 2025
2 parents 06bcd20 + ee0a922 commit e1e1530
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ Considering we want to buffer the location of our ports by 50 meters. Looking in
Therefore, we need to cast our points from the location colum to geography before handing them over to the buffer function:
```php
$bufferedPorts = Port::query()
->select(new Aliased(ST::buffer(new AsGeography('location'), 50), alias: 'buffered_location'))
->select(new Aliased(ST::buffer(new AsGeography('location'), 50), as: 'buffered_location'))
->withCasts(['buffered_location' => Polygon::class])
->get();
```
Expand Down
12 changes: 6 additions & 6 deletions src/Database/Builder/EloquentBuilderMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ public function withMagellanCasts(): \Closure
$columns = $this->toBase()->columns ?? [];
foreach ($columns as $column) {

/** @var string|null $alias */
$alias = null;
/** @var string|null $as */
$as = null;
/** @var MagellanBaseExpression|null $magellanExpression */
$magellanExpression = null;

if ($column instanceof Aliased && $column->expression instanceof MagellanBaseExpression) {
$alias = $column->alias;
$as = $column->as;
$magellanExpression = $column->expression;
} elseif ($column instanceof MagellanBaseExpression) {
$alias = strtolower($column->postgisFunction);
$as = strtolower($column->postgisFunction);
$magellanExpression = $column;
}

if ($magellanExpression?->returnsBbox()) {
$this->withCasts([$alias => BBoxCast::class]);
$this->withCasts([$as => BBoxCast::class]);
}

if ($magellanExpression?->returnsGeometry()) {
$this->withCasts([$alias => Geometry::class]);
$this->withCasts([$as => Geometry::class]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Database/Expressions/Aliased.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class Aliased implements ExpressionContract

public function __construct(
public string|ExpressionContract $expression,
public string $alias,
public string $as,
) {
}

public function getValue(Grammar $grammar): string
{
$expression = $this->stringize($grammar, $this->expression);
$wrappedAlias = $grammar->wrap($this->alias);
$wrappedAs = $grammar->wrap($this->as);

return "$expression AS $wrappedAlias";
return "$expression AS $wrappedAs";
}
}

0 comments on commit e1e1530

Please sign in to comment.