Skip to content

Commit fc03ad4

Browse files
committed
Fix Blueprint constructor for cross-compatibility
1 parent 6afee49 commit fc03ad4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Schema/Blueprint.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Connection;
88
use Illuminate\Database\Schema\Blueprint as SchemaBlueprint;
99
use MongoDB\Collection;
10+
use ReflectionMethod;
1011

1112
use function array_flip;
1213
use function implode;
@@ -18,6 +19,8 @@
1819

1920
class Blueprint extends SchemaBlueprint
2021
{
22+
private static bool $hasConnectionInConstructor;
23+
2124
/**
2225
* The MongoDB connection object for this blueprint.
2326
*/
@@ -40,9 +43,19 @@ class Blueprint extends SchemaBlueprint
4043
/**
4144
* Create a new schema blueprint.
4245
*/
43-
public function __construct(Connection $connection, string $collection)
46+
public function __construct(Connection $connection, string $collection, ?Closure $callback = null)
4447
{
45-
parent::__construct($connection, $collection);
48+
// Parent constructor signature was changed in Laravel 12
49+
// https://github.com/laravel/framework/commit/f29df4740d724f1c36385c9989569e3feb9422df#diff-68f714a9f1b751481b993414d3f1300ad55bcef12084ec0eb8f47f350033c24bR107
50+
self::$hasConnectionInConstructor ??= (new ReflectionMethod(parent::class, '__construct'))->getParameters()[0]->getName() === 'connection';
51+
52+
if (self::$hasConnectionInConstructor) {
53+
// Laravel 12 and after
54+
parent::__construct($connection, $collection, $callback);
55+
} else {
56+
// Laravel 11 and before
57+
parent::__construct($collection, $callback);
58+
}
4659

4760
$this->connection = $connection;
4861

0 commit comments

Comments
 (0)