Skip to content

Conversation

finagin
Copy link
Contributor

@finagin finagin commented Apr 30, 2025

Bug

The facade \Illuminate\Support\Facades\Schema calls db.schema, which is not a singleton. As a result, calling Schema::blueprintResolver has no effect.

Solution

Adding the static modifier will make the property accessible across all instances. Furthermore, allowing blueprintResolver to accept null values will provide the ability to revert to the default builder if the custom builder was intended for single-use only.

Compatibility

Since this functionality is currently not fully operational, fixing this bug does not pose any compatibility issues.

@taylorotwell
Copy link
Member

But facades cache their own copy of the resolved instance, regardless of binding type?

CleanShot 2025-04-30 at 08 55 21@2x

@finagin
Copy link
Contributor Author

finagin commented Apr 30, 2025

Hi @taylorotwell
The Schema facade uses cache property with a value of false, which prevents it from being cached, in the code below the one you showed in the screenshot.

class Schema extends Facade
{
/**
* Indicates if the resolved facade should be cached.
*
* @var bool
*/
protected static $cached = false;

protected static function resolveFacadeInstance($name)
{
if (isset(static::$resolvedInstance[$name])) {
return static::$resolvedInstance[$name];
}
if (static::$app) {
if (static::$cached) {
return static::$resolvedInstance[$name] = static::$app[$name];
}
return static::$app[$name];
}
}

@finagin
Copy link
Contributor Author

finagin commented Apr 30, 2025

I don't see the reason for prohibiting caching for this facade. However, considering that this feature first appeared for this facade, there is probably a valid reason for it. Perhaps the author of this feature can help us, @driesvints.

@taylorotwell taylorotwell merged commit ea9c481 into laravel:12.x Apr 30, 2025
60 checks passed
@rodrigopedra
Copy link
Contributor

As a workaround, until this is published, you can call this from a Service Provider's register() method:

$this->callAfterResolving('db.schema', function ($schemaBuilder) {
    $schemaBuilder->blueprintResolver(function ($connection, $table, $callback) {
        // ...
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants