|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Config\Repository; |
|
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
6
|
|
|
use Illuminate\Support\Facades\Schema; |
|
7
|
|
|
|
|
8
|
|
|
class CreateMobileVerificationTokensTable extends Migration |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var Repository |
|
12
|
|
|
*/ |
|
13
|
|
|
private $userTable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var Repository |
|
17
|
|
|
*/ |
|
18
|
|
|
private $tokenTable; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Repository |
|
22
|
|
|
*/ |
|
23
|
|
|
private $mobileColumn; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* CreateMobileVerificationTokensTable constructor. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->userTable = config('mobile_verifier.user_table', 'users'); |
|
31
|
|
|
$this->mobileColumn = config('mobile_verifier.mobile_column', 'mobile'); |
|
32
|
|
|
$this->tokenTable = config('mobile_verifier.token_table', 'mobile_verification_tokens'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Run the migrations. |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function up(): void |
|
41
|
|
|
{ |
|
42
|
|
|
Schema::create($this->tokenTable, static function (Blueprint $table) { |
|
|
|
|
|
|
43
|
|
|
$table->increments('id'); |
|
44
|
|
|
$table->string('mobile')->index(); |
|
45
|
|
|
$table->string('token', 10)->index(); |
|
46
|
|
|
$table->timestamp('expires_at')->nullable(); |
|
47
|
|
|
|
|
48
|
|
|
$table->index(['mobile', 'token']); |
|
49
|
|
|
}); |
|
50
|
|
|
|
|
51
|
|
|
if (!Schema::hasColumn($this->userTable, $this->mobileColumn)) { |
|
|
|
|
|
|
52
|
|
|
Schema::table($this->userTable, function (Blueprint $table) { |
|
|
|
|
|
|
53
|
|
|
$table->string($this->mobileColumn); |
|
|
|
|
|
|
54
|
|
|
}); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (!Schema::hasColumn($this->userTable, 'mobile_verified_at')) { |
|
58
|
|
|
Schema::table($this->userTable, function (Blueprint $table) { |
|
59
|
|
|
$table->timestamp('mobile_verified_at')->nullable()->after($this->mobileColumn); |
|
|
|
|
|
|
60
|
|
|
}); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Reverse the migrations. |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function down(): void |
|
70
|
|
|
{ |
|
71
|
|
|
Schema::drop($this->tokenTable); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
Schema::table($this->userTable, static function (Blueprint $table) { |
|
|
|
|
|
|
74
|
|
|
$table->dropColumn('mobile_verified_at'); |
|
75
|
|
|
}); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|