Skip to content

Commit 0f3fae0

Browse files
committedJun 15, 2024
add opt generation table and add tel number
1 parent 9801436 commit 0f3fae0

4 files changed

+69
-6
lines changed
 

‎app/Models/OtpGeneration.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
8+
class OtpGeneration extends Model
9+
{
10+
protected $fillable = [
11+
'code',
12+
'token',
13+
'expire_at',
14+
'user_id',
15+
];
16+
17+
protected static function booted(): void
18+
{
19+
static::creating(static function ($model) {
20+
$model->expire_at = now()->addMinutes(2);
21+
});
22+
}
23+
24+
public function user(): BelongsTo
25+
{
26+
return $this->belongsTo(User::class);
27+
}
28+
29+
protected function casts(): array
30+
{
31+
return [
32+
'expire_at' => 'timestamp',
33+
];
34+
}
35+
}

‎app/Models/User.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class User extends Authenticatable
2020
protected $fillable = [
2121
'name',
2222
'email',
23+
'tel',
2324
'password',
2425
];
2526

‎database/migrations/0001_01_01_000000_create_users_table.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('users', function (Blueprint $table) {
14+
Schema::create('users', static function (Blueprint $table) {
1515
$table->id();
16-
$table->string('name');
17-
$table->string('email')->unique();
16+
$table->string('name')->nullable();
17+
$table->string('email')->unique()->nullable();
18+
$table->string('tel')->unique();
1819
$table->timestamp('email_verified_at')->nullable();
19-
$table->string('password');
20+
$table->string('password')->nullable();
2021
$table->rememberToken();
2122
$table->timestamps();
2223
});
2324

24-
Schema::create('password_reset_tokens', function (Blueprint $table) {
25+
Schema::create('password_reset_tokens', static function (Blueprint $table) {
2526
$table->string('email')->primary();
2627
$table->string('token');
2728
$table->timestamp('created_at')->nullable();
2829
});
2930

30-
Schema::create('sessions', function (Blueprint $table) {
31+
Schema::create('sessions', static function (Blueprint $table) {
3132
$table->string('id')->primary();
3233
$table->foreignId('user_id')->nullable()->index();
3334
$table->string('ip_address', 45)->nullable();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('otp_generations', static function (Blueprint $table) {
11+
$table->id();
12+
$table->unsignedBigInteger('user_id');
13+
$table->bigInteger('code');
14+
$table->string('token');
15+
$table->timestamp('expire_at');
16+
$table->timestamps();
17+
18+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
19+
});
20+
}
21+
22+
public function down(): void
23+
{
24+
Schema::dropIfExists('otp_generations');
25+
}
26+
};

0 commit comments

Comments
 (0)
Please sign in to comment.