44
55namespace MongoDB \Laravel \Schema ;
66
7- use Closure ;
8- use Illuminate \Database \Connection ;
9- use Illuminate \Database \Schema \Blueprint as SchemaBlueprint ;
7+ use Illuminate \Database \Schema \Blueprint as BaseBlueprint ;
108use MongoDB \Collection ;
11- use ReflectionMethod ;
9+ use MongoDB \ Laravel \ Connection ;
1210
1311use function array_flip ;
1412use function implode ;
1816use function is_string ;
1917use function key ;
2018
21- class Blueprint extends SchemaBlueprint
19+ /** @property Connection $connection */
20+ class Blueprint extends BaseBlueprint
2221{
23- private static bool $ hasConnectionInConstructor ;
24-
25- /**
26- * The MongoDB connection object for this blueprint.
27- */
28- protected Connection $ connection ;
22+ // Import $connection property and constructor for Laravel 12 compatibility
23+ use BlueprintLaravelCompatibility;
2924
3025 /**
3126 * The MongoDB collection object for this blueprint.
32- * Type added in Laravel 12.
3327 *
3428 * @var Collection
3529 */
36- protected Collection $ collection ;
30+ protected $ collection ;
3731
3832 /**
3933 * Fluent columns.
@@ -42,28 +36,6 @@ class Blueprint extends SchemaBlueprint
4236 */
4337 protected $ columns = [];
4438
45- /**
46- * Create a new schema blueprint.
47- */
48- public function __construct (Connection $ connection , string $ collection , ?Closure $ callback = null )
49- {
50- // Parent constructor signature was changed in Laravel 12
51- // https://github.com/laravel/framework/commit/f29df4740d724f1c36385c9989569e3feb9422df#diff-68f714a9f1b751481b993414d3f1300ad55bcef12084ec0eb8f47f350033c24bR107
52- self ::$ hasConnectionInConstructor ??= (new ReflectionMethod (parent ::class, '__construct ' ))->getParameters ()[0 ]->getName () === 'connection ' ;
53-
54- if (self ::$ hasConnectionInConstructor ) {
55- // Laravel 12 and after
56- parent ::__construct ($ connection , $ collection , $ callback );
57- } else {
58- // Laravel 11 and before
59- parent ::__construct ($ collection , $ callback );
60- }
61-
62- $ this ->connection = $ connection ;
63-
64- $ this ->collection = $ this ->connection ->getCollection ($ collection );
65- }
66-
6739 /** @inheritdoc */
6840 public function index ($ columns = null , $ name = null , $ algorithm = null , $ options = [])
6941 {
0 commit comments