|
6 | 6 | use Illuminate\Auth\Passwords\CanResetPassword;
|
7 | 7 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
8 | 8 | use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
| 9 | +use Illuminate\Database\Eloquent\Casts\Attribute; |
9 | 10 | use Illuminate\Notifications\Notifiable;
|
| 11 | +use Illuminate\Support\Str; |
10 | 12 | use Jenssegers\Mongodb\Eloquent\HybridRelations;
|
11 | 13 | use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
|
12 | 14 |
|
|
21 | 23 | * @property \Carbon\Carbon $birthday
|
22 | 24 | * @property \Carbon\Carbon $created_at
|
23 | 25 | * @property \Carbon\Carbon $updated_at
|
| 26 | + * @property string $username |
24 | 27 | */
|
25 | 28 | class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract
|
26 | 29 | {
|
27 |
| - use Authenticatable, CanResetPassword, HybridRelations, Notifiable; |
| 30 | + use Authenticatable; |
| 31 | + use CanResetPassword; |
| 32 | + use HybridRelations; |
| 33 | + use Notifiable; |
28 | 34 |
|
29 | 35 | protected $connection = 'mongodb';
|
30 | 36 | protected $dates = ['birthday', 'entry.date'];
|
@@ -84,4 +90,12 @@ protected function serializeDate(DateTimeInterface $date)
|
84 | 90 | {
|
85 | 91 | return $date->format('l jS \of F Y h:i:s A');
|
86 | 92 | }
|
| 93 | + |
| 94 | + protected function username(): Attribute |
| 95 | + { |
| 96 | + return Attribute::make( |
| 97 | + get: fn ($value) => $value, |
| 98 | + set: fn ($value) => Str::slug($value) |
| 99 | + ); |
| 100 | + } |
87 | 101 | }
|
0 commit comments