Skip to content

Commit 0b9f1c4

Browse files
committed
Merge remote-tracking branch 'origin/support/laravel-13' into 5.x
2 parents 92ed64f + de5086b commit 0b9f1c4

1 file changed

Lines changed: 13 additions & 26 deletions

File tree

docs/upgrading.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,50 +96,37 @@ InspireCMS v4 supports both Laravel 12 and Laravel 13.
9696

9797
### What changed
9898

99-
To avoid Laravel 13 model boot recursion errors (for example: `bootIfNotBooted` called while a model is still booting), model observer registration was centralized in service providers.
99+
To avoid Laravel 13 model boot recursion errors (for example: `bootIfNotBooted` called while a model is still booting), observer registration was changed from using `Model::observe()` to direct event listener registration within trait boot methods.
100100

101-
Observer registration now happens in:
101+
Event listeners are now registered directly in trait boot methods instead of using `Model::observe()`.
102102

103-
- `InspireCmsServiceProvider::registerModelObservers()` (core models)
104-
- `InspireCmsSupportServiceProvider::registerModelObservers()` (support models)
103+
### If you use traits with observer patterns
105104

106-
### If you override model classes
107-
108-
If you override model classes via InspireCMS config/model manifest, keep observer registration in the provider layer. Avoid registering observers inside model `boot()`, `booted()`, or trait boot methods for the same model.
105+
When using traits that register observers, register event listeners directly in the trait's boot method instead of using `Model::observe()`.
109106

110107
Example migration pattern:
111108

112-
Before (model-level registration):
109+
Before (using observe):
113110

114111
```php
115-
protected static function booted()
112+
public static function bootYourTrait()
116113
{
117-
static::observe(ContentObserver::class);
114+
static::observe(YourObserver::class);
118115
}
119116
```
120117

121-
After (provider-level registration):
118+
After (using event listeners):
122119

123120
```php
124-
protected function registerModelObservers(): void
121+
public static function bootYourTrait()
125122
{
126-
InspireCmsConfig::getContentModelClass()::observe(ContentObserver::class);
123+
static::created(fn ($model) => (new YourObserver)->created($model));
124+
static::updated(fn ($model) => (new YourObserver)->updated($model));
125+
static::deleted(fn ($model) => (new YourObserver)->deleted($model));
127126
}
128127
```
129128

130-
If your custom model uses traits that previously registered observers in trait boot methods, move those observer registrations to the same provider method as well.
131-
132-
### Recommended dependency constraints
133-
134-
Use composer constraints that allow both versions:
135-
136-
```json
137-
"laravel/framework": "^12.0|^13.0"
138-
```
139-
140-
### Recommended CI matrix
141-
142-
Run your package test suite against both Laravel versions, ideally with both lowest and stable dependency sets, to catch compatibility regressions early.
129+
If your model has multiple trait-boot observers, register each trait's listeners separately in its own boot method.
143130

144131
---
145132

0 commit comments

Comments
 (0)