File tree 4 files changed +69
-6
lines changed
4 files changed +69
-6
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class User extends Authenticatable
20
20
protected $ fillable = [
21
21
'name ' ,
22
22
'email ' ,
23
+ 'tel ' ,
23
24
'password ' ,
24
25
];
25
26
Original file line number Diff line number Diff line change 11
11
*/
12
12
public function up (): void
13
13
{
14
- Schema::create ('users ' , function (Blueprint $ table ) {
14
+ Schema::create ('users ' , static function (Blueprint $ table ) {
15
15
$ 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 ();
18
19
$ table ->timestamp ('email_verified_at ' )->nullable ();
19
- $ table ->string ('password ' );
20
+ $ table ->string ('password ' )-> nullable () ;
20
21
$ table ->rememberToken ();
21
22
$ table ->timestamps ();
22
23
});
23
24
24
- Schema::create ('password_reset_tokens ' , function (Blueprint $ table ) {
25
+ Schema::create ('password_reset_tokens ' , static function (Blueprint $ table ) {
25
26
$ table ->string ('email ' )->primary ();
26
27
$ table ->string ('token ' );
27
28
$ table ->timestamp ('created_at ' )->nullable ();
28
29
});
29
30
30
- Schema::create ('sessions ' , function (Blueprint $ table ) {
31
+ Schema::create ('sessions ' , static function (Blueprint $ table ) {
31
32
$ table ->string ('id ' )->primary ();
32
33
$ table ->foreignId ('user_id ' )->nullable ()->index ();
33
34
$ table ->string ('ip_address ' , 45 )->nullable ();
Original file line number Diff line number Diff line change
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
+ };
You can’t perform that action at this time.
0 commit comments