Skip to content

Commit

Permalink
Merge pull request #52 from ebbbang/master
Browse files Browse the repository at this point in the history
Issue #51 : Use separate password_resets_table for each
  • Loading branch information
Hesto committed Jan 8, 2017
2 parents 6232092 + 065057c commit 0c4f2a0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Commands/MultiAuthInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function fire()
]);

$this->installMigration();
$this->installPasswordResetMigration();
}

if(!$this->option('views')) {
Expand Down Expand Up @@ -180,6 +181,35 @@ public function installMigration()
return true;
}

/**
* Install PasswordResetMigration.
*
* @return bool
*/
public function installPasswordResetMigration()
{
$name = $this->getParsedNameInput();

$migrationDir = base_path() . '/database/migrations/';
$migrationName = 'create_' . str_singular(snake_case($name)) .'_password_resets_table.php';
$migrationStub = new SplFileInfo(__DIR__ . '/../stubs/Model/PasswordResetMigration.stub');

$files = $this->files->allFiles($migrationDir);

foreach ($files as $file) {
if(str_contains($file->getFilename(), $migrationName)) {
$this->putFile($file->getPathname(), $migrationStub);

return true;
}
}

$path = $migrationDir . date('Y_m_d_His', strtotime('+1 second')) . '_' . $migrationName;
$this->putFile($path, $migrationStub);

return true;
}

/**
* Get the console command options.
*
Expand Down
31 changes: 31 additions & 0 deletions src/stubs/Model/PasswordResetMigration.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Create{{singularClass}}PasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('{{singularSnake}}_password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('created_at')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('{{singularSnake}}_password_resets');
}
}
2 changes: 1 addition & 1 deletion src/stubs/config/passwords.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

'{{pluralSnake}}' => [
'provider' => '{{pluralSnake}}',
'table' => 'password_resets',
'table' => '{{singularSnake}}_password_resets',
'expire' => 60,
],

0 comments on commit 0c4f2a0

Please sign in to comment.