Skip to content

Commit 1e0d7c7

Browse files
committed
User model changes
1 parent 7bbb03c commit 1e0d7c7

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed

app/Models/User.php

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

77
// use Illuminate\Contracts\Auth\MustVerifyEmail;
8+
use Illuminate\Database\Eloquent\Concerns\HasUuids;
89
use Illuminate\Database\Eloquent\Factories\HasFactory;
910
use Illuminate\Foundation\Auth\User as Authenticatable;
1011
use Illuminate\Notifications\Notifiable;
1112
use Laravel\Sanctum\HasApiTokens;
1213

13-
class User extends Authenticatable
14+
final class User extends Authenticatable
1415
{
1516
use HasApiTokens;
1617
use HasFactory;
18+
use HasUuids;
1719
use Notifiable;
1820

19-
/**
20-
* The attributes that are mass assignable.
21-
*
22-
* @var array<int, string>
23-
*/
2421
protected $fillable = [
2522
'name',
2623
'email',
2724
'password',
2825
];
2926

30-
/**
31-
* The attributes that should be hidden for serialization.
32-
*
33-
* @var array<int, string>
34-
*/
3527
protected $hidden = [
3628
'password',
37-
'remember_token',
3829
];
3930

40-
/**
41-
* The attributes that should be cast.
42-
*
43-
* @var array<string, string>
44-
*/
4531
protected $casts = [
4632
'email_verified_at' => 'datetime',
4733
];

database/factories/UserFactory.php

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,32 @@
44

55
namespace Database\Factories;
66

7+
use App\Models\User;
78
use Illuminate\Database\Eloquent\Factories\Factory;
8-
use Illuminate\Support\Str;
9+
use Illuminate\Support\Facades\Hash;
910

10-
/**
11-
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
12-
*/
13-
class UserFactory extends Factory
11+
final class UserFactory extends Factory
1412
{
15-
/**
16-
* Define the model's default state.
17-
*
18-
* @return array<string, mixed>
19-
*/
13+
protected $model = User::class;
14+
2015
public function definition(): array
2116
{
2217
return [
23-
'name' => fake()->name(),
24-
'email' => fake()->unique()->safeEmail(),
18+
'name' => $this->faker->name(),
19+
'email' => $this->faker->unique()->safeEmail(),
2520
'email_verified_at' => now(),
26-
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
27-
'remember_token' => Str::random(10),
21+
'password' => Hash::make(
22+
value: 'password',
23+
),
2824
];
2925
}
3026

31-
/**
32-
* Indicate that the model's email address should be unverified.
33-
*/
34-
public function unverified(): static
27+
public function unverified(): UserFactory
3528
{
36-
return $this->state(fn (array $attributes) => [
37-
'email_verified_at' => null,
38-
]);
29+
return $this->state(
30+
state: fn (array $attributes): array => [
31+
'email_verified_at' => null,
32+
],
33+
);
3934
}
4035
}

database/seeders/DatabaseSeeder.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44

55
namespace Database\Seeders;
66

7-
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
7+
use App\Models\User;
88
use Illuminate\Database\Seeder;
99

10-
class DatabaseSeeder extends Seeder
10+
final class DatabaseSeeder extends Seeder
1111
{
12-
/**
13-
* Seed the application's database.
14-
*/
1512
public function run(): void
1613
{
17-
// \App\Models\User::factory(10)->create();
18-
19-
// \App\Models\User::factory()->create([
20-
// 'name' => 'Test User',
21-
// 'email' => '[email protected]',
22-
// ]);
14+
User::factory()->create([
15+
'name' => 'Steve McDougall',
16+
'email' => '[email protected]',
17+
]);
2318
}
2419
}

0 commit comments

Comments
 (0)