Skip to content

Commit

Permalink
fix: provide laravel 9-supported facade accessor for custom schema bu…
Browse files Browse the repository at this point in the history
…ilder
  • Loading branch information
Luke committed Apr 29, 2022
1 parent 356a482 commit 531ed57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/app/Providers/BluewingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bluewing\Providers;

use Bluewing\Database\PostgresConnection as BluewingPostgresConnection;
use Bluewing\Schema\Schema;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;
Expand All @@ -14,7 +15,7 @@ class BluewingServiceProvider extends ServiceProvider {
*/
public function register()
{

$this->app->bind('db.schema', fn() => Schema::customizedSchemaBuilder());
}

/**
Expand Down
28 changes: 10 additions & 18 deletions src/app/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,38 @@
use Bluewing\Schema\Blueprint as BluewingBlueprint;

/**
* Class Schema
*
* @package Bluewing\Schema
*
* Subclass of `Schema` that returns the appropriate instance of `Blueprint` containing
* additional utility functions.
* Subclass of `Schema` that returns the appropriate instance of `Blueprint` containing additional utility functions.
*
* @see https://stackoverflow.com/questions/22444685/extend-blueprint-class/57539154#57539154
*/
class Schema extends BaseSchema
{

/**
* Get a schema builder instance for a connection.
*
* @param string|null $name
* @param string|null $name
*
* @return Builder
*/
public static function connection($name): Builder
{
/** @var Builder $builder */
$builder = static::$app['db']->connection($name)->getSchemaBuilder();
$builder->blueprintResolver(static function($table, $callback) {
return new BluewingBlueprint($table, $callback);
});
return $builder;
return static::customizedSchemaBuilder($name);
}

/**
* Get a schema builder instance for the default connection.
* Retrieves an instance of the schema `Builder` with a customized `Blueprint` class.
*
* @param string|null $name
*
* @return Builder
*/
protected static function getFacadeAccessor(): Builder
public static function customizedSchemaBuilder(string|null $name = null): Builder
{
/** @var Builder $builder */
$builder = static::$app['db']->connection()->getSchemaBuilder();
$builder->blueprintResolver(static function($table, $callback) {
return new BluewingBlueprint($table, $callback);
});
$builder = static::$app['db']->connection($name)->getSchemaBuilder();
$builder->blueprintResolver(static fn($table, $callback) => new BluewingBlueprint($table, $callback));
return $builder;
}
}

0 comments on commit 531ed57

Please sign in to comment.