Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert model DB connection customization #38

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions packages/core/config/laravel-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,14 @@

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.
*
* @return void
*/
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();
Expand All @@ -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');
}
}
39 changes: 27 additions & 12 deletions packages/core/src/LaravelAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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');
}
}
}
8 changes: 0 additions & 8 deletions packages/core/src/MultiFactorCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion packages/core/templates/Database/User.bladetmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
19 changes: 0 additions & 19 deletions packages/core/tests/Unit/DatabaseMigrationTest.php

This file was deleted.

10 changes: 0 additions & 10 deletions packages/core/tests/Unit/MultiFactorCredentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down