Skip to content

Commit cfad38a

Browse files
committed
feat(auth): scaffold user model and migration
1 parent bdc8ea5 commit cfad38a

3 files changed

Lines changed: 76 additions & 17 deletions

File tree

app/Models/User.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,50 @@
55
namespace App\Models;
66

77
use Carbon\CarbonInterface;
8+
use Database\Factories\UserFactory;
9+
use Illuminate\Database\Eloquent\Attributes\Hidden;
10+
use Illuminate\Database\Eloquent\Concerns\HasUlids;
811
use Illuminate\Database\Eloquent\Factories\HasFactory;
912
use Illuminate\Foundation\Auth\User as Authenticatable;
1013

1114
/**
12-
* @property-read int $id
15+
* @property-read string $id
1316
* @property-read string $name
17+
* @property-read string|null $display_name
1418
* @property-read string $email
19+
* @property-read string|null $notification_email
1520
* @property-read CarbonInterface|null $email_verified_at
21+
* @property-read CarbonInterface|null $notification_email_verified_at
1622
* @property-read string $password
23+
* @property-read string|null $remember_token
24+
* @property-read string|null $two_factor_secret
25+
* @property-read string|null $two_factor_recovery_codes
26+
* @property-read CarbonInterface|null $two_factor_confirmed_at
1727
* @property-read CarbonInterface $created_at
1828
* @property-read CarbonInterface $updated_at
1929
*/
30+
#[Hidden(['password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes'])]
2031
final class User extends Authenticatable
2132
{
22-
/** @use HasFactory<\Database\Factories\UserFactory> */
33+
/** @use HasFactory<UserFactory> */
2334
use HasFactory;
35+
use HasUlids;
2436

25-
/**
26-
* The attributes that should be hidden for serialization.
27-
*
28-
* @var list<string>
29-
*/
30-
protected $hidden = [
31-
'password',
32-
];
33-
34-
/**
35-
* Get the attributes that should be cast.
36-
*
37-
* @return array<string, string>
38-
*/
3937
protected function casts(): array
4038
{
4139
return [
42-
'id' => 'int',
40+
'id' => 'string',
4341
'name' => 'string',
42+
'display_name' => 'string',
4443
'email' => 'string',
44+
'notification_email' => 'string',
4545
'email_verified_at' => 'datetime',
46+
'notification_email_verified_at' => 'datetime',
4647
'password' => 'hashed',
48+
'remember_token' => 'string',
49+
'two_factor_secret' => 'encrypted',
50+
'two_factor_recovery_codes' => 'encrypted',
51+
'two_factor_confirmed_at' => 'datetime',
4752
'created_at' => 'datetime',
4853
'updated_at' => 'datetime',
4954
];
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*/
14+
public function up(): void
15+
{
16+
Schema::create('users', function (Blueprint $table): void {
17+
$table->ulid('id')->primary();
18+
$table->string('name');
19+
$table->string('display_name')->nullable();
20+
$table->string('email')->unique();
21+
$table->string('notification_email')->nullable();
22+
$table->timestamp('email_verified_at')->nullable();
23+
$table->timestamp('notification_email_verified_at')->nullable();
24+
$table->string('password');
25+
$table->rememberToken();
26+
$table->text('two_factor_secret')->nullable();
27+
$table->text('two_factor_recovery_codes')->nullable();
28+
$table->timestamp('two_factor_confirmed_at')->nullable();
29+
$table->timestamps();
30+
});
31+
}
32+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*/
14+
public function up(): void
15+
{
16+
Schema::create('password_reset_tokens', function (Blueprint $table): void {
17+
$table->string('email')->primary();
18+
$table->string('token');
19+
$table->timestamp('created_at')->nullable();
20+
});
21+
}
22+
};

0 commit comments

Comments
 (0)