Skip to content

Commit

Permalink
Change how we get a table's columns
Browse files Browse the repository at this point in the history
The `doctrine/dbal` package was removed in Laravel 11, which meant the `getDoctrineSchemaManager` method was removed.

Instead, we can use `Schema::getColumns()` from laravel/framework#49020 , which was released in Laravel 10.34.
  • Loading branch information
duncanmcclean committed Apr 6, 2024
1 parent 97d8c06 commit 74f3237
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require": {
"php": "^8.2",
"laravel/framework": "^10.0 || ^11.0",
"laravel/framework": "^10.34 || ^11.0",
"mollie/mollie-api-php": "^2.30.0",
"moneyphp/money": "^4.0",
"paypal/paypal-checkout-sdk": "^1.0",
Expand Down
14 changes: 4 additions & 10 deletions src/Customers/EloquentCustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,10 @@ public function delete(Customer $customer): void
*/
protected function getCustomColumns(): array
{
$tableColumns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns((new $this->model)->getTable());

return collect($tableColumns)
->reject(function (Column $column) {
return in_array($column->getName(), $this->knownColumns);
})
->map->getName()
->toArray();
return collect(Schema::getColumns((new $this->model)->getTable()))
->reject(fn (array $column) => in_array($column['name'], $this->knownColumns))
->map(fn (array $column) => $column['name'])
->all();
}

public static function bindings(): array
Expand Down
8 changes: 3 additions & 5 deletions src/Customers/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ protected function column($column)
protected function columnExists(string $column): bool
{
$databaseColumns = Blink::once("DatabaseColumns_{$this->builder->getModel()->getTable()}", function () {
$columns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns($this->builder->getModel()->getTable());

return collect($columns)->map->getName()->values();
return collect(Schema::getColumns($this->builder->getModel()->getTable()))
->map(fn (array $column) => $column['name'])
->all();
});

return $databaseColumns->contains($column);
Expand Down
14 changes: 4 additions & 10 deletions src/Orders/EloquentOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,10 @@ public function delete($order): void
*/
protected function getCustomColumns(): array
{
$tableColumns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns((new $this->model)->getTable());

return collect($tableColumns)
->reject(function (Column $column) {
return in_array($column->getName(), $this->knownColumns);
})
->map->getName()
->toArray();
return collect(Schema::getColumns((new $this->model)->getTable()))
->reject(fn (array $column) => in_array($column['name'], $this->knownColumns))
->map(fn (array $column) => $column['name'])
->all();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Orders/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ public function whereStatusLogDate(OrderStatus|PaymentStatus $status, Carbon $da
protected function columnExists(string $column): bool
{
$databaseColumns = Blink::once("DatabaseColumns_{$this->builder->getModel()->getTable()}", function () {
$columns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns($this->builder->getModel()->getTable());

return collect($columns)->map->getName()->values();
return collect(Schema::getColumns($this->builder->getModel()->getTable()))
->map(fn (array $column) => $column['name'])
->all();
});

return $databaseColumns->contains($column);
Expand Down

0 comments on commit 74f3237

Please sign in to comment.