Skip to content

Commit 1ce5500

Browse files
Laravel 13.x Compatibility (#1044)
* Bump dependencies for Laravel 13 * Update GitHub Actions for Laravel 13 * Fix YAML syntax for branch patterns and Laravel versions * Update AuditableObserver registration to use class name * Delay AuditableObserver registration until booted * Refactor bootAuditable to register observer conditionally * My bad Removed unnecessary closing brace in Auditable.php. * Make phpstan happy * Update version range --------- Co-authored-by: erikn69 <erikn_69@hotmail.com>
1 parent 73e710f commit 1ce5500

7 files changed

Lines changed: 27 additions & 11 deletions

File tree

.github/workflows/phpstan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727

2828
- name: Install larastan
2929
run: |
30-
composer require "larastan/larastan" --no-update
30+
composer require --dev "larastan/larastan" --no-update
3131
composer update --prefer-dist --no-suggest
3232
3333
- name: Run PHPStan
34-
run: ./vendor/bin/phpstan --error-format=github
34+
run: ./vendor/bin/phpstan analyse --error-format=github --no-progress

.github/workflows/run-tests.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ on:
1111
jobs:
1212
run-tests:
1313
runs-on: ubuntu-latest
14+
1415
timeout-minutes: 15
16+
1517
env:
1618
COMPOSER_NO_INTERACTION: 1
19+
1720
strategy:
1821
fail-fast: false
1922
matrix:
20-
php: [ 8.2, 8.3, 8.4, 8.5 ]
21-
laravel: [ 11.*, 12.* ]
23+
php: [8.2, 8.3, 8.4, 8.5]
24+
laravel: [11.*, 12.*, 13.*]
2225
include:
2326
- laravel: 12.*
2427
testbench: 10.*
2528
- laravel: 11.*
2629
testbench: 9.*
30+
- laravel: 13.*
31+
testbench: 11.*
32+
exclude:
33+
- laravel: 13.*
34+
php: 8.2
2735

2836
name: PHP${{ matrix.php }} - Laravel${{ matrix.laravel }} - ${{ matrix.dependency-version }}
2937

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Thank you for choosing OwenIt\LaravelAuditing!
2626

2727
Version | Illuminate | Status | PHP Version
2828
:----------|:---------------|:------------------------|:------------
29-
14.x | 11.x.x - 12.x.x | Active support :rocket: | > = 8.2
29+
14.x | 11.x.x - 13.x.x | Active support :rocket: | > = 8.2
3030
13.x | 7.x.x - 11.x.x | End of life | > = 7.3 \| 8.0
3131
12.x | 6.x.x - 9.x.x | End of life | > = 7.3 \| 8.0
3232
11.x | 5.8.x - 8.x.x | End of life | > = 7.3

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
"require": {
4242
"php": "^8.2",
4343
"ext-json": "*",
44-
"illuminate/console": "^11.0|^12.0",
45-
"illuminate/database": "^11.0|^12.0",
46-
"illuminate/filesystem": "^11.0|^12.0"
44+
"illuminate/console": "^11.0|^12.0|^13.0",
45+
"illuminate/database": "^11.0|^12.0|^13.0",
46+
"illuminate/filesystem": "^11.0|^12.0|^13.0"
4747
},
4848
"require-dev": {
4949
"mockery/mockery": "^1.5.1",
50-
"orchestra/testbench": "^9.0|^10.0",
51-
"phpunit/phpunit": "^11.0"
50+
"orchestra/testbench": "^9.0|^10.0|^11.0",
51+
"phpunit/phpunit": "^11.0|^12.5.12"
5252
},
5353
"autoload": {
5454
"psr-4": {

src/Auditable.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ trait Auditable
7878
public static function bootAuditable()
7979
{
8080
if (App::getFacadeRoot() && static::isAuditingEnabled()) {
81-
static::observe(new AuditableObserver);
81+
$registerObserver = fn() => static::observe(AuditableObserver::class);
82+
83+
if (method_exists(static::class, 'whenBooted')) {
84+
static::whenBooted($registerObserver);
85+
} else {
86+
$registerObserver(); // fallback for Laravel 11
87+
}
8288
}
8389
}
8490

src/AuditableObserver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ protected function dispatchAudit(Auditable $model): void
115115
*/
116116
protected function fireDispatchingAuditEvent(Auditable $model): bool
117117
{
118+
// @phpstan-ignore-next-line
118119
return app()->make('events')
119120
->until(new DispatchingAudit($model)) !== false;
120121
}

src/Auditor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ protected function createDatabaseDriver(): Database
105105
*/
106106
protected function fireAuditingEvent(Auditable $model, AuditDriver $driver): bool
107107
{
108+
// @phpstan-ignore-next-line
108109
return $this
109110
->container
110111
->make('events')

0 commit comments

Comments
 (0)