diff --git a/packages/core/config/laravel-auth.php b/packages/core/config/laravel-auth.php index a79cd8c..a73347f 100644 --- a/packages/core/config/laravel-auth.php +++ b/packages/core/config/laravel-auth.php @@ -7,20 +7,6 @@ return [ - /* - |-------------------------------------------------------------------------- - | Laravel Auth Database Connection - |-------------------------------------------------------------------------- - | - | This configuration value allows you to customize the database connection - | that should be used by the laravel-auth's internal database models. - | - */ - - 'database' => [ - 'connection' => env('DB_CONNECTION', 'mysql'), - ], - /* |-------------------------------------------------------------------------- | Laravel Auth Public Key Credential Settings (WebAuthn) diff --git a/packages/core/database/migrations/2022_02_08_000002_create_multi_factor_credentials_table.php b/packages/core/database/migrations/2022_02_08_000002_create_multi_factor_credentials_table.php index bc46e88..2c81bc4 100644 --- a/packages/core/database/migrations/2022_02_08_000002_create_multi_factor_credentials_table.php +++ b/packages/core/database/migrations/2022_02_08_000002_create_multi_factor_credentials_table.php @@ -6,23 +6,6 @@ class CreateMultiFactorCredentialsTable extends Migration { - /** - * The database schema. - * - * @var \Illuminate\Database\Schema\Builder - */ - protected $schema; - - /** - * Create a new migration instance. - * - * @return void - */ - public function __construct() - { - $this->schema = Schema::connection($this->getConnection()); - } - /** * Run the migrations. * @@ -30,7 +13,7 @@ public function __construct() */ public function up() { - $this->schema->create('multi_factor_credentials', function (Blueprint $table) { + Schema::create('multi_factor_credentials', function (Blueprint $table) { $table->string('id')->primary(); $table->string('type'); $table->unsignedBigInteger('user_id')->nullable()->index(); @@ -47,16 +30,6 @@ public function up() */ public function down() { - $this->schema->dropIfExists('multi_factor_credentials'); - } - - /** - * Get the migration connection name. - * - * @return string|null - */ - public function getConnection() - { - return config('laravel-auth.database.connection') ?? $this->connection; + Schema::dropIfExists('multi_factor_credentials'); } } diff --git a/packages/core/src/LaravelAuthServiceProvider.php b/packages/core/src/LaravelAuthServiceProvider.php index 95a6f1c..7f5ae31 100644 --- a/packages/core/src/LaravelAuthServiceProvider.php +++ b/packages/core/src/LaravelAuthServiceProvider.php @@ -15,14 +15,9 @@ class LaravelAuthServiceProvider extends ServiceProvider */ public function boot(): void { - $this->loadTranslationsFrom(__DIR__.'/../lang', 'laravel-auth'); - - if ($this->app->runningInConsole()) { - $this->publishes([__DIR__.'/../config/laravel-auth.php' => config_path('laravel-auth.php')], 'laravel-auth-package'); - $this->publishes([__DIR__.'/../lang' => $this->languagePath('vendor/laravel-auth')], 'laravel-auth-package'); - - $this->registerMigrations(); - } + $this->registerResources(); + $this->registerMigrations(); + $this->registerPublishing(); } /** @@ -36,21 +31,41 @@ public function register(): void $this->app->bind(WebAuthnContract::class, SpomkyWebAuthn::class); } + /** + * Register the Laravel Auth resources. + */ + protected function registerResources(): void + { + $this->loadTranslationsFrom(__DIR__.'/../lang', 'laravel-auth'); + } + /** * Register the Laravel Auth migration files. */ protected function registerMigrations(): void { - if (LaravelAuth::$runsMigrations) { + if ($this->app->runningInConsole() && LaravelAuth::$runsMigrations) { $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } } /** - * Determines the path to the application's language files. + * Register the package's publishable resources. */ - protected function languagePath(string $path): string + protected function registerPublishing(): void { - return function_exists('lang_path') ? lang_path($path) : resource_path('lang/'.$path); + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../config/laravel-auth.php' => config_path('laravel-auth.php'), + ], 'laravel-auth-config'); + + $this->publishes([ + __DIR__.'/../lang' => lang_path('vendor/laravel-auth'), + ], 'laravel-auth-translations'); + + $this->publishes([ + __DIR__.'/../database/migrations' => database_path('migrations'), + ], 'laravel-auth-migrations'); + } } } diff --git a/packages/core/src/MultiFactorCredential.php b/packages/core/src/MultiFactorCredential.php index 84b3d39..03564b2 100644 --- a/packages/core/src/MultiFactorCredential.php +++ b/packages/core/src/MultiFactorCredential.php @@ -88,12 +88,4 @@ public function user() return $this->belongsTo($model, 'user_id', (new $model())->getKeyName()); } - - /** - * Get the current connection name for the model. - */ - public function getConnectionName(): ?string - { - return Config::get('laravel-auth.database.connection') ?? $this->connection; - } } diff --git a/packages/core/templates/Database/User.bladetmpl b/packages/core/templates/Database/User.bladetmpl index 92e3fec..0b76797 100644 --- a/packages/core/templates/Database/User.bladetmpl +++ b/packages/core/templates/Database/User.bladetmpl @@ -84,7 +84,7 @@ class User extends Authenticatable /** * Get the prunable model query. * - * {!! ! '@' !!}return \Illuminate\Database\Eloquent\Builder + * {!! '@' !!}return \Illuminate\Database\Eloquent\Builder */ public function prunable() { diff --git a/packages/core/tests/Unit/DatabaseMigrationTest.php b/packages/core/tests/Unit/DatabaseMigrationTest.php deleted file mode 100644 index e42fa57..0000000 --- a/packages/core/tests/Unit/DatabaseMigrationTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertSame('testbench', (new CreateMultiFactorCredentialsTable())->getConnection()); - - config(['laravel-auth.database.connection' => null]); - - $this->assertNull((new CreateMultiFactorCredentialsTable())->getConnection()); - } -} diff --git a/packages/core/tests/Unit/MultiFactorCredentialTest.php b/packages/core/tests/Unit/MultiFactorCredentialTest.php index 6de54f9..8324091 100644 --- a/packages/core/tests/Unit/MultiFactorCredentialTest.php +++ b/packages/core/tests/Unit/MultiFactorCredentialTest.php @@ -43,16 +43,6 @@ public function it_can_customize_the_user_relationship_model_based_on_the_standa $this->assertTrue($credential->user->is($user)); } - /** @test */ - public function it_can_customize_the_database_connection(): void - { - $this->assertSame('testbench', (new MultiFactorCredential())->getConnectionName()); - - config(['laravel-auth.database.connection' => null]); - - $this->assertNull((new MultiFactorCredential())->getConnectionName()); - } - /** @test */ public function it_does_not_expose_the_secret_when_serialized(): void {