From 4569c8b36170a8352d16ea028baa0d34b1e5506b Mon Sep 17 00:00:00 2001 From: Watheq Alshowaiter Date: Fri, 22 May 2026 22:58:22 +0300 Subject: [PATCH 1/5] feat: support laravel 13 --- .github/workflows/test-matrix.yml | 6 +++++- README.md | 4 ++-- composer.json | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-matrix.yml b/.github/workflows/test-matrix.yml index 4019df2..ee244e7 100644 --- a/.github/workflows/test-matrix.yml +++ b/.github/workflows/test-matrix.yml @@ -14,9 +14,13 @@ jobs: strategy: fail-fast: false matrix: - laravel: [12.*, 11.*, 10.*, 9.*, 8.*, 7.*, 6.*] + laravel: [13.*, 12.*, 11.*, 10.*, 9.*, 8.*, 7.*, 6.*] include: + - laravel: 13.* + testbench: 11.* + php: 8.4 + - laravel: 12.* testbench: 10.* php: 8.4 diff --git a/README.md b/README.md index f19f56f..77152d8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![StandWithPalestine][ico-palestine]][link-palestine] [![ko-fi][ico-ko-fi]][link-ko-fi] -[ico-laravel]: https://img.shields.io/badge/Laravel-%E2%89%A56.0-ff2d20?style=flat-square&logo=laravel +[ico-laravel]: https://img.shields.io/badge/Laravel-6.0%20--%2013.0-ff2d20?style=flat-square&logo=laravel [ico-php]: https://img.shields.io/packagist/php-v/watheqalshowaiter/model-fields?color=%238892BF&style=flat-square&logo=php [ico-version]: https://img.shields.io/packagist/v/watheqalshowaiter/model-fields.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/watheqalshowaiter/model-fields.svg?style=flat-square&color=%23007ec6 @@ -430,7 +430,7 @@ So Briefly, This package is useful if: ## Features -✅ Supports Laravel versions: 12, 11, 10, 9, 8, 7, and 6. +✅ Supports Laravel versions: 13, 12, 11, 10, 9, 8, 7, and 6. ✅ Supports PHP versions: 8.4, 8.3, 8.2, 8.1, 8.0, and 7.4. diff --git a/composer.json b/composer.json index 769bba5..8059443 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,11 @@ ], "require": { "php": ">=7.4", - "illuminate/contracts": "^12.0||^11.0||^10.0||^9.0||^8.0||^7.0||^6.0||^5.0" + "illuminate/contracts": "^13.0||^12.0||^11.0||^10.0||^9.0||^8.0||^7.0||^6.0||^5.0" }, "require-dev": { - "nunomaduro/collision": "^8.1.1||^7.10.0||^6.0||^5.0||^4.0||^3.2", - "orchestra/testbench": "^10.0||^9.0.0||^8.22.0||^7.0||^6.0||^5.0||^4.0" + "nunomaduro/collision": "^9.0||^8.1.1||^7.10.0||^6.0||^5.0||^4.0||^3.2", + "orchestra/testbench": "^11.0||^10.0||^9.0.0||^8.22.0||^7.0||^6.0||^5.0||^4.0" }, "replace": { "watheqalshowaiter/model-requierd-fields": "*" From 263d3b8a1a0fd3c5b471e775a66b5c07fa84f7af Mon Sep 17 00:00:00 2001 From: Watheq Alshowaiter Date: Sat, 23 May 2026 10:26:22 +0300 Subject: [PATCH 2/5] fix: nunomaduro/collision dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8059443..b37a986 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "illuminate/contracts": "^13.0||^12.0||^11.0||^10.0||^9.0||^8.0||^7.0||^6.0||^5.0" }, "require-dev": { - "nunomaduro/collision": "^9.0||^8.1.1||^7.10.0||^6.0||^5.0||^4.0||^3.2", + "nunomaduro/collision": "^8.1.1||^7.10.0||^6.0||^5.0||^4.0||^3.2", "orchestra/testbench": "^11.0||^10.0||^9.0.0||^8.22.0||^7.0||^6.0||^5.0||^4.0" }, "replace": { From 825c4bf9ca45694a4b3ae3447841b4856c12da05 Mon Sep 17 00:00:00 2001 From: Watheq Alshowaiter Date: Thu, 18 Jun 2026 23:08:41 +0300 Subject: [PATCH 3/5] feat: support laravel 13 --- src/FieldsService.php | 5 +---- src/ModelFieldsServiceProvider.php | 7 +++--- src/Support/Helpers.php | 34 +++++++++++++++++++++++++++--- tests/Models/Uncle.php | 19 ++++++++++++++--- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/FieldsService.php b/src/FieldsService.php index b19ed03..259c537 100644 --- a/src/FieldsService.php +++ b/src/FieldsService.php @@ -86,9 +86,7 @@ public function requiredFields() $observerDefaultAttributes = Helpers::getObserverFilledFields($this->modelClass); $primaryIndex = $this->primaryField(); - $table = Helpers::getTableFromThisModel($this->modelClass); - return collect(Schema::getColumns($table)) ->map(function ($column) { // specific to mariadb if ($column['default'] == 'NULL') { @@ -259,8 +257,7 @@ public function applicationDefaultFields() { $this->throwIfNotUsingModelMethodFirst(); - $modelInstance = new $this->modelClass; - $attributes = collect($modelInstance->getAttributes())->filter()->keys()->toArray(); // ignore null values + $attributes = collect(Helpers::getModelAttributes($this->modelClass))->filter()->keys()->toArray(); // ignore null values $observerDefaultAttributes = Helpers::getObserverFilledFields($this->modelClass); $allFields = $this->allFields(); diff --git a/src/ModelFieldsServiceProvider.php b/src/ModelFieldsServiceProvider.php index 3c5e599..1e37f9a 100644 --- a/src/ModelFieldsServiceProvider.php +++ b/src/ModelFieldsServiceProvider.php @@ -592,10 +592,9 @@ public function boot() }); Builder::macro('applicationDefaultFields', function () { - $modelClass = $this->getModel(); - $modelInstance = new $modelClass; - $attributes = collect($modelInstance->getAttributes())->filter()->keys()->toArray(); // ignore null values - $observerDefaultAttributes = Helpers::getObserverFilledFields($this->getModel()); + $model = $this->getModel(); + $attributes = collect(Helpers::getModelAttributes($model))->filter()->keys()->toArray(); // ignore null values + $observerDefaultAttributes = Helpers::getObserverFilledFields($model); $allFields = $this->allFields(); diff --git a/src/Support/Helpers.php b/src/Support/Helpers.php index d3926db..25a8632 100644 --- a/src/Support/Helpers.php +++ b/src/Support/Helpers.php @@ -5,6 +5,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Event; +use ReflectionClass; +use ReflectionException; /** * Here are the shared logic across multiple files, now are FieldsService & ModelFieldsServiceProvider @@ -24,16 +26,25 @@ public static function isLaravelVersionLessThan10() */ public static function getModelDefaultAttributes($model) { - return array_keys((new $model)->getAttributes()); + return array_keys(static::getModelAttributes($model)); } public static function getTableFromThisModel($model) { - $table = (new $model)->getTable(); + $table = static::getModelWithoutBooting($model)->getTable(); return str_replace('.', '__', $table); } + /** + * @return array + * @throws ReflectionException + */ + public static function getModelAttributes($model) + { + return static::getModelWithoutBooting($model)->getAttributes(); + } + /** * Get fields that are automatically filled by model observers/events * during 'creating' and 'saving' events @@ -44,7 +55,7 @@ public static function getTableFromThisModel($model) public static function getObserverFilledFields($modelOrClass) { if ($modelOrClass instanceof Model) { - $model = $modelOrClass->newInstance(); // fresh instance of same model + $model = clone $modelOrClass; $modelClass = get_class($modelOrClass); } else { $model = new $modelOrClass; @@ -63,4 +74,21 @@ public static function getObserverFilledFields($modelOrClass) return array_keys($dirtyNoNull); } + + /** + * Get a model for passive metadata inspection without starting its boot cycle. + * + * @return object + * @throws ReflectionException + */ + protected static function getModelWithoutBooting($modelOrClass) + { + if ($modelOrClass instanceof Model) { + return $modelOrClass; + } + + $reflection = new ReflectionClass($modelOrClass); + + return $reflection->newInstanceWithoutConstructor(); + } } diff --git a/tests/Models/Uncle.php b/tests/Models/Uncle.php index fbcf78c..e917227 100644 --- a/tests/Models/Uncle.php +++ b/tests/Models/Uncle.php @@ -19,13 +19,26 @@ protected static function boot(): void { parent::boot(); - self::observe(UncleObserver::class); + if (method_exists(static::class, 'whenBooted')) { + static::whenBooted(function () { + static::registerDefaultFieldEvents(); + }); - self::creating(function ($model) { + return; + } + + static::registerDefaultFieldEvents(); + } + + protected static function registerDefaultFieldEvents(): void + { + static::observe(UncleObserver::class); + + static::creating(function ($model) { $model->boot_creating = 'creating'; }); - self::saving(function ($model) { + static::saving(function ($model) { $model->boot_saving = 'saving'; }); } From 18705d87d7c0ec271684894a6530877d40062cb3 Mon Sep 17 00:00:00 2001 From: WatheqAlshowaiter <24838274+WatheqAlshowaiter@users.noreply.github.com> Date: Thu, 18 Jun 2026 20:09:16 +0000 Subject: [PATCH 4/5] Fix styling --- src/FieldsService.php | 1 + src/Support/Helpers.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/FieldsService.php b/src/FieldsService.php index 259c537..05aff75 100644 --- a/src/FieldsService.php +++ b/src/FieldsService.php @@ -87,6 +87,7 @@ public function requiredFields() $primaryIndex = $this->primaryField(); $table = Helpers::getTableFromThisModel($this->modelClass); + return collect(Schema::getColumns($table)) ->map(function ($column) { // specific to mariadb if ($column['default'] == 'NULL') { diff --git a/src/Support/Helpers.php b/src/Support/Helpers.php index 25a8632..75db5c4 100644 --- a/src/Support/Helpers.php +++ b/src/Support/Helpers.php @@ -38,6 +38,7 @@ public static function getTableFromThisModel($model) /** * @return array + * * @throws ReflectionException */ public static function getModelAttributes($model) @@ -79,6 +80,7 @@ public static function getObserverFilledFields($modelOrClass) * Get a model for passive metadata inspection without starting its boot cycle. * * @return object + * * @throws ReflectionException */ protected static function getModelWithoutBooting($modelOrClass) From cff3f08d7fc5c1b1ca19315b7235de309a018221 Mon Sep 17 00:00:00 2001 From: WatheqAlshowaiter <24838274+WatheqAlshowaiter@users.noreply.github.com> Date: Thu, 18 Jun 2026 20:39:05 +0000 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 156a6c4..788f7ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `model-required-fields` will be documented in this file. +## 3.2.2 - 2026-06-18 + +### What's Changed + +* Support laravel 13 + +**Full Changelog**: https://github.com/WatheqAlshowaiter/model-fields/compare/3.2.1...3.2.2 + ## 3.2.1 - 2025-11-08 ### What's Changed