Skip to content

Commit

Permalink
feat(Laravel): add support for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
alibori committed Mar 8, 2024
1 parent 5d41456 commit 713e917
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-api-resource-generator` will be documented in this file.

## 1.3.2 - 2024-03-08

### Added

- Added support for **Laravel 11**

## 1.3.1 - 2023-07-29

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
"license": "MIT",
"require": {
"php": ">=8.1",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"doctrine/dbal": "^2.9|^2.10|^3.0",
"illuminate/database": "^9.1|^9.2|^10.0",
"illuminate/database": "^9.1|^9.2|^10.0|^11.0",
"barryvdh/reflection-docblock": "^2.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"orchestra/testbench": "^7.22",
"orchestra/testbench": "^7.22|^8.11|^9.0",
"laravel/pint": "^1.6",
"pestphp/pest": "^1.22",
"pestphp/pest-plugin-laravel": "^1.4"
Expand Down
25 changes: 21 additions & 4 deletions src/Console/GenerateApiResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ protected function getPropertiesFromTable(Model $model): void
$table = $model->getConnection()->getTablePrefix().$model->getTable();

try {
$schema = $model->getConnection()->getDoctrineSchemaManager();
// Check if getDoctrineSchemaManager method exists to deal with Laravel 11 upgrade
if (method_exists($model->getConnection(), 'getDoctrineSchemaManager')) {
$schema = $model->getConnection()->getDoctrineSchemaManager();
} else {
$schema = $model->getConnection()->getSchemaBuilder();
}
} catch (Exception $exception) {
$this->error($exception->getMessage());

Expand All @@ -139,15 +144,27 @@ protected function getPropertiesFromTable(Model $model): void
[$database, $table] = explode('.', $table);
}

$columns = $schema->listTableColumns($table, $database);
//$columns = $schema->listTableColumns($table, $database);
// Check if listTableColumns method exists to deal with Laravel 11 upgrade
if (method_exists($schema, 'listTableColumns')) {
$columns = $schema->listTableColumns($table, $database);
} else {
$columns = $schema->getColumns($table);
}

if ( ! $columns) {
return;
}

foreach ($columns as $column) {
$field = $column->getName();
$type = $column->getType()->getName();
// Check if $column is an array to deal with Laravel 11 upgrade
if (is_array($column)) {
$field = $column['name'];
$type = $column['type'];
} else {
$field = $column->getName();
$type = $column->getType()->getName();
}

$field_type = match ($type) {
'string', 'text', 'date', 'time', 'guid', 'datetimetz', 'datetime', 'decimal' => 'string',
Expand Down

0 comments on commit 713e917

Please sign in to comment.