From 8965bc9e2bfff8779ec7cf1122b9a6ae6c6029ad Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 26 Dec 2023 16:05:02 -0300 Subject: [PATCH 1/8] Add Support Laravel 11 --- .github/workflows/code-style.yml | 7 ++-- .github/workflows/cypress.yml | 7 ++-- .github/workflows/mysql.yml | 5 ++- .github/workflows/pgsql.yml | 5 ++- .github/workflows/phpstan.yml | 2 +- .github/workflows/sqlite.yml | 5 ++- composer.json | 3 +- src/Commands/Actions/FillableTable.php | 47 ++++++++++---------------- src/Commands/CreateCommand.php | 7 ++-- src/DataSource/Support/Sql.php | 10 +++--- 10 files changed, 48 insertions(+), 50 deletions(-) diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 973115d5..d6c34f9d 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -18,8 +18,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 8.2 ] - laravel: [ 10.* ] + php: [ 8.2, 8.1 ] + laravel: [ 11.*, 10.* ] + exclude: + - php: 8.1 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index acbf28a7..6e620a08 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -29,8 +29,11 @@ jobs: strategy: matrix: - php: [ 8.2 ] - laravel: [ 10.* ] + php: [ 8.2, 8.1 ] + laravel: [ 11.*, 10.* ] + exclude: + - php: 8.1 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index e9a8083b..a5bbea2a 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -30,7 +30,10 @@ jobs: strategy: matrix: php: [ 8.2, 8.1 ] - laravel: [ 10.* ] + laravel: [ 11.*, 10.* ] + exclude: + - php: 8.1 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml index bb7e09a6..0cf98624 100644 --- a/.github/workflows/pgsql.yml +++ b/.github/workflows/pgsql.yml @@ -31,7 +31,10 @@ jobs: strategy: matrix: php: [ 8.2, 8.1 ] - laravel: [ 10.* ] + laravel: [ 11.*, 10.* ] + exclude: + - php: 8.1 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 85c4c982..604632c9 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php: [ 8.2 ] - laravel: [ 10.* ] + laravel: [ 11.*, 10.* ] dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index 4a4894c0..abd32459 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -19,7 +19,10 @@ jobs: strategy: matrix: php: [ 8.2, 8.1 ] - laravel: [ 10.* ] + laravel: [ 11.*, 10.* ] + exclude: + - php: 8.1 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }} diff --git a/composer.json b/composer.json index dd6747a0..16d920e6 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ ], "require": { "php": "^8.1", - "doctrine/dbal": "^3.7", - "livewire/livewire": "^3.1.0", + "livewire/livewire": "^3.3|dev-feat/l11", "laravel/prompts": "^0.1.13" }, "require-dev": { diff --git a/src/Commands/Actions/FillableTable.php b/src/Commands/Actions/FillableTable.php index 926cfbd7..9e6e0db2 100644 --- a/src/Commands/Actions/FillableTable.php +++ b/src/Commands/Actions/FillableTable.php @@ -2,7 +2,6 @@ namespace PowerComponents\LivewirePowerGrid\Commands\Actions; -use Doctrine\DBAL\Exception; use Illuminate\Support\Facades\{File, Schema}; use Illuminate\Support\Str; @@ -50,45 +49,40 @@ public static function eloquentBuilder(string $modelQualifiedName, string $model continue; } - $conn = $model->getConnection(); + $connection = Schema::connection($model->getConnection()->getName()); - $conn->getDoctrineSchemaManager() - ->getDatabasePlatform() - ->registerDoctrineTypeMapping('enum', 'string'); - - $hasColumn = function () use ($model, $field, $conn) { + $hasColumn = function () use ($model, $field, $connection) { try { - return Schema::connection($conn->getDatabaseName()) - ->hasColumn($model->getTable(), $field); + return $connection->hasColumn($model->getTable(), $field); } catch (\Exception) { return Schema::hasColumn($model->getTable(), $field); } }; if ($hasColumn()) { - $column = $conn->getDoctrineColumn($model->getTable(), $field); + $columnType = $connection->getColumnType($model->getTable(), $field); $title = Str::of($field)->replace('_', ' ')->ucfirst(); - if (in_array($column->getType()->getName(), ['datetime', 'date'])) { + if (in_array($columnType, ['datetime', 'date', 'timestamp'])) { $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '_formatted\', \'' . $field . '\')' . "\n" . ' ->sortable(),' . "\n\n"; } - if ($column->getType()->getName() === 'datetime') { + if ($columnType === 'datetime') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '_formatted\', fn (' . $modelUnqualifiedName . ' $model) => Carbon::parse($model->' . $field . ')->format(\'d/m/Y H:i:s\'))'; $filters .= ' Filter::datetimepicker(\'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'date') { + if ($columnType === 'date') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '_formatted\', fn (' . $modelUnqualifiedName . ' $model) => Carbon::parse($model->' . $field . ')->format(\'d/m/Y\'))'; $filters .= ' Filter::datepicker(\'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'boolean') { + if ($columnType === 'boolean') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\')' . "\n" . ' ->toggleable(),' . "\n\n"; $filters .= ' Filter::boolean(\'' . $field . '\'),' . "\n"; @@ -96,14 +90,14 @@ public static function eloquentBuilder(string $modelQualifiedName, string $model continue; } - if (in_array($column->getType()->getName(), ['smallint', 'integer', 'bigint'])) { + if (in_array($columnType, ['smallint', 'integer', 'bigint'])) { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'string') { + if ($columnType === 'string') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\')' . "\n" . ' ->sortable()' . "\n" . ' ->searchable(),' . "\n\n"; $filters .= ' Filter::inputText(\'' . $field . '\')->operators([\'contains\']),' . "\n"; @@ -139,7 +133,6 @@ public static function eloquentBuilder(string $modelQualifiedName, string $model * @param string $databaseTableName * @param string|null $stubFile * @return string - * @throws Exception */ public static function queryBuilder(string $databaseTableName, string $stubFile = null): string { @@ -152,35 +145,29 @@ public static function queryBuilder(string $databaseTableName, string $stubFile $filters = "[\n"; foreach ($columnListing as $field) { - $conn = Schema::getConnection(); - - $conn->getDoctrineSchemaManager() - ->getDatabasePlatform() - ->registerDoctrineTypeMapping('enum', 'string'); - - $column = $conn->getDoctrineColumn($databaseTableName, $field); + $columnType = Schema::getColumnType($databaseTableName, $field); $title = Str::of($field)->replace('_', ' ')->ucfirst(); - if (in_array($column->getType()->getName(), ['datetime', 'date'])) { + if (in_array($columnType, ['datetime', 'date'])) { $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '_formatted\', \'' . $field . '\')' . "\n" . ' ->sortable(),' . "\n\n"; } - if ($column->getType()->getName() === 'datetime') { + if ($columnType === 'datetime') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '_formatted\', fn ($model) => Carbon::parse($model->' . $field . ')->format(\'d/m/Y H:i:s\'))'; $filters .= ' Filter::datetimepicker(\'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'date') { + if ($columnType === 'date') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '_formatted\', fn ($model) => Carbon::parse($model->' . $field . ')->format(\'d/m/Y\'))'; $filters .= ' Filter::datepicker(\'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'boolean') { + if ($columnType === 'boolean') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\')' . "\n" . ' ->toggleable(),' . "\n\n"; $filters .= ' Filter::boolean(\'' . $field . '\'),' . "\n"; @@ -188,14 +175,14 @@ public static function queryBuilder(string $databaseTableName, string $stubFile continue; } - if (in_array($column->getType()->getName(), ['smallint', 'integer', 'bigint'])) { + if (in_array($columnType, ['smallint', 'integer', 'bigint'])) { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\'),' . "\n"; continue; } - if ($column->getType()->getName() === 'string') { + if ($columnType === 'string') { $datasource .= "\n" . ' ->addColumn(\'' . $field . '\')'; $columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\')' . "\n" . ' ->sortable()' . "\n" . ' ->searchable(),' . "\n\n"; $filters .= ' Filter::inputText(\'' . $field . '\')->operators([\'contains\']),' . "\n"; diff --git a/src/Commands/CreateCommand.php b/src/Commands/CreateCommand.php index b116752e..37e7684b 100644 --- a/src/Commands/CreateCommand.php +++ b/src/Commands/CreateCommand.php @@ -2,7 +2,6 @@ namespace PowerComponents\LivewirePowerGrid\Commands; -use Doctrine\DBAL\Exception; use Illuminate\Console\Command; use Illuminate\Support\Facades\{File, Schema}; use Illuminate\Support\{Arr, Str}; @@ -132,8 +131,6 @@ protected function askDatasource(): void /** * @throws CreateCommandException - * @throws Exception - * @throws \Exception */ protected function askModel(): void { @@ -142,9 +139,9 @@ protected function askModel(): void if (strtolower($this->datasourceOption) === 'm') { $this->model = suggest( label: 'Enter your Model name or file path', - required: true, - default: 'User', options: Models::list(), + default: 'User', + required: true, ); $this->modelPath = explode('\\', $this->model); diff --git a/src/DataSource/Support/Sql.php b/src/DataSource/Support/Sql.php index 9c9407b5..e3e27570 100644 --- a/src/DataSource/Support/Sql.php +++ b/src/DataSource/Support/Sql.php @@ -128,14 +128,14 @@ public static function getSortFieldType(string $sortField): ?string return null; } + $tableName = $data[0]; + $column = $data[1]; + if (!Schema::hasColumn($data[0], $data[1])) { - throw new Exception("There is no column with name '$data[1]' on table '$data[0]'. Please see: https://livewire-powergrid.com/#/table/include-columns?id=fieldstring-field-string-datafield"); + throw new Exception("There is no column with name '$column' on table '$tableName'. Please see: https://livewire-powergrid.com/#/table/include-columns?id=fieldstring-field-string-datafield"); } - return Schema::getConnection() - ->getDoctrineColumn($data[0], $data[1]) - ->getType() - ->getName(); + return Schema::getColumnType($tableName, $column); } /** From d4c6adb7d582c741e9532be7c2eb0b0001d707e8 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 26 Dec 2023 16:05:35 -0300 Subject: [PATCH 2/8] Add Support Laravel 11 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 16d920e6..275d6507 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "spaze/phpstan-disallowed-calls": "^2.16.1", "larastan/larastan": "^2.7", "pestphp/pest": "^2.28.1", - "orchestra/testbench": "^8.17" + "orchestra/testbench": "^8.17|^9.0" }, "suggest": { "openspout/openspout": "Required to export XLS and CSV" From 7f7f85c239e249caf6cbbedb91735499f0ffb77b Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 26 Dec 2023 16:09:31 -0300 Subject: [PATCH 3/8] WIP --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 275d6507..d3fa28f5 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "require-dev": { "composer/composer": "^2.6.6", "laravel/pint": "^1.13.7", - "laradumps/laradumps-core": "^0.3.0", "spaze/phpstan-disallowed-calls": "^2.16.1", "larastan/larastan": "^2.7", "pestphp/pest": "^2.28.1", From 123fa3105e20d7a9ead4f0845fe04c64e7b0cc94 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 26 Dec 2023 16:21:08 -0300 Subject: [PATCH 4/8] Update dependencies --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d3fa28f5..75de6e5b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "require": { "php": "^8.1", "livewire/livewire": "^3.3|dev-feat/l11", - "laravel/prompts": "^0.1.13" + "laravel/prompts": "^0.1.13", + "laradumps/laradumps-core": "^1.0|dev-update-dependencies" }, "require-dev": { "composer/composer": "^2.6.6", From e5a3d43d395c56ae870bedce3214a51379d9d7f4 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 26 Dec 2023 16:22:02 -0300 Subject: [PATCH 5/8] Update dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 75de6e5b..e1f5d3cb 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ "require": { "php": "^8.1", "livewire/livewire": "^3.3|dev-feat/l11", - "laravel/prompts": "^0.1.13", - "laradumps/laradumps-core": "^1.0|dev-update-dependencies" + "laravel/prompts": "^0.1.13" }, "require-dev": { "composer/composer": "^2.6.6", @@ -29,7 +28,8 @@ "spaze/phpstan-disallowed-calls": "^2.16.1", "larastan/larastan": "^2.7", "pestphp/pest": "^2.28.1", - "orchestra/testbench": "^8.17|^9.0" + "orchestra/testbench": "^8.17|^9.0", + "laradumps/laradumps-core": "^1.0|dev-update-dependencies" }, "suggest": { "openspout/openspout": "Required to export XLS and CSV" From d9a32610cbf857e4978b11fab3a7652e29c1cb61 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Thu, 28 Dec 2023 16:05:27 -0300 Subject: [PATCH 6/8] pint --- src/Commands/Actions/FillableTable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Commands/Actions/FillableTable.php b/src/Commands/Actions/FillableTable.php index 27231193..dc2270fe 100644 --- a/src/Commands/Actions/FillableTable.php +++ b/src/Commands/Actions/FillableTable.php @@ -144,7 +144,6 @@ public static function queryBuilder(string $databaseTableName, string $stubFile $columns = "[\n"; $filters = "[\n"; - $filteredColumns = collect($columnListing) ->filter(function ($column) { return !in_array($column, ['password', 'remember_token', 'email_verified_at']); From f0ee7c388950a241e0b968dbedec3d4341cd4071 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Tue, 2 Jan 2024 20:49:23 -0300 Subject: [PATCH 7/8] update dependencies --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cd6a9546..96086cf5 100644 --- a/composer.json +++ b/composer.json @@ -19,14 +19,13 @@ ], "require": { "php": "^8.1", - "livewire/livewire": "^3.3|dev-feat/l11", + "livewire/livewire": "^3.3", "laravel/prompts": "^0.1.13" }, "require-dev": { "composer/composer": "^2.6.6", "laravel/pint": "^1.13.7", "laradumps/laradumps-core": "^1.1", - "spaze/phpstan-disallowed-calls": "^2.16.1", "larastan/larastan": "^2.7", "pestphp/pest": "^2.28.1", From 90fdeaeda5325f5766e504548b8020a76fba3aae Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Wed, 3 Jan 2024 17:00:51 -0300 Subject: [PATCH 8/8] WIP --- .github/workflows/cypress.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 6e620a08..4c3fb4a3 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -34,6 +34,8 @@ jobs: exclude: - php: 8.1 laravel: 11.* + - php: 8.2 + laravel: 11.* dependency-version: [ prefer-stable ] name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}