Skip to content

Commit 713e917

Browse files
committed
feat(Laravel): add support for Laravel 11
1 parent 5d41456 commit 713e917

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

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

5+
## 1.3.2 - 2024-03-08
6+
7+
### Added
8+
9+
- Added support for **Laravel 11**
10+
511
## 1.3.1 - 2023-07-29
612

713
### Fixed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
"license": "MIT",
3535
"require": {
3636
"php": ">=8.1",
37-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
38-
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0",
39-
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0",
37+
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
38+
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
39+
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
4040
"doctrine/dbal": "^2.9|^2.10|^3.0",
41-
"illuminate/database": "^9.1|^9.2|^10.0",
41+
"illuminate/database": "^9.1|^9.2|^10.0|^11.0",
4242
"barryvdh/reflection-docblock": "^2.1"
4343
},
4444
"minimum-stability": "dev",
4545
"prefer-stable": true,
4646
"require-dev": {
47-
"orchestra/testbench": "^7.22",
47+
"orchestra/testbench": "^7.22|^8.11|^9.0",
4848
"laravel/pint": "^1.6",
4949
"pestphp/pest": "^1.22",
5050
"pestphp/pest-plugin-laravel": "^1.4"

src/Console/GenerateApiResourceCommand.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ protected function getPropertiesFromTable(Model $model): void
117117
$table = $model->getConnection()->getTablePrefix().$model->getTable();
118118

119119
try {
120-
$schema = $model->getConnection()->getDoctrineSchemaManager();
120+
// Check if getDoctrineSchemaManager method exists to deal with Laravel 11 upgrade
121+
if (method_exists($model->getConnection(), 'getDoctrineSchemaManager')) {
122+
$schema = $model->getConnection()->getDoctrineSchemaManager();
123+
} else {
124+
$schema = $model->getConnection()->getSchemaBuilder();
125+
}
121126
} catch (Exception $exception) {
122127
$this->error($exception->getMessage());
123128

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

142-
$columns = $schema->listTableColumns($table, $database);
147+
//$columns = $schema->listTableColumns($table, $database);
148+
// Check if listTableColumns method exists to deal with Laravel 11 upgrade
149+
if (method_exists($schema, 'listTableColumns')) {
150+
$columns = $schema->listTableColumns($table, $database);
151+
} else {
152+
$columns = $schema->getColumns($table);
153+
}
143154

144155
if ( ! $columns) {
145156
return;
146157
}
147158

148159
foreach ($columns as $column) {
149-
$field = $column->getName();
150-
$type = $column->getType()->getName();
160+
// Check if $column is an array to deal with Laravel 11 upgrade
161+
if (is_array($column)) {
162+
$field = $column['name'];
163+
$type = $column['type'];
164+
} else {
165+
$field = $column->getName();
166+
$type = $column->getType()->getName();
167+
}
151168

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

0 commit comments

Comments
 (0)