2
2
3
3
namespace App \Models ;
4
4
5
- // use Illuminate\Contracts\Auth\MustVerifyEmail ;
5
+ use Illuminate \Database \ Eloquent \ Casts \ Attribute ;
6
6
use Illuminate \Database \Eloquent \Factories \HasFactory ;
7
7
use Illuminate \Foundation \Auth \User as Authenticatable ;
8
8
use Illuminate \Notifications \Notifiable ;
9
+ use JoelButcher \Socialstream \HasConnectedAccounts ;
10
+ use JoelButcher \Socialstream \SetsProfilePhotoFromUrl ;
11
+ use Laravel \Fortify \TwoFactorAuthenticatable ;
12
+ use Laravel \Jetstream \HasProfilePhoto ;
9
13
use Laravel \Sanctum \HasApiTokens ;
10
14
11
15
class User extends Authenticatable
12
16
{
13
- use HasApiTokens, HasFactory, Notifiable;
17
+ use HasApiTokens;
18
+ use HasConnectedAccounts;
19
+ use HasFactory;
20
+ use HasProfilePhoto {
21
+ HasProfilePhoto::profilePhotoUrl as getPhotoUrl;
22
+ }
23
+ use Notifiable;
24
+ use SetsProfilePhotoFromUrl;
25
+ use TwoFactorAuthenticatable;
14
26
15
27
/**
16
28
* The attributes that are mass assignable.
@@ -24,22 +36,45 @@ class User extends Authenticatable
24
36
];
25
37
26
38
/**
27
- * The attributes that should be hidden for serialization .
39
+ * The attributes that should be hidden for arrays .
28
40
*
29
41
* @var array<int, string>
30
42
*/
31
43
protected $ hidden = [
32
44
'password ' ,
33
45
'remember_token ' ,
46
+ 'two_factor_recovery_codes ' ,
47
+ 'two_factor_secret ' ,
34
48
];
35
49
36
50
/**
37
- * The attributes that should be cast .
51
+ * The accessors to append to the model's array form .
38
52
*
39
- * @var array<string , string>
53
+ * @var array<int , string>
40
54
*/
41
- protected $ casts = [
42
- 'email_verified_at ' => 'datetime ' ,
43
- 'password ' => 'hashed ' ,
55
+ protected $ appends = [
56
+ 'profile_photo_url ' ,
44
57
];
58
+
59
+ /**
60
+ * Get the attributes that should be cast.
61
+ *
62
+ * @return array<string, string>
63
+ */
64
+ protected function casts (): array
65
+ {
66
+ return [
67
+ 'email_verified_at ' => 'datetime ' ,
68
+ ];
69
+ }
70
+
71
+ /**
72
+ * Get the URL to the user's profile photo.
73
+ */
74
+ public function profilePhotoUrl (): Attribute
75
+ {
76
+ return filter_var ($ this ->profile_photo_path , FILTER_VALIDATE_URL )
77
+ ? Attribute::get (fn () => $ this ->profile_photo_path )
78
+ : $ this ->getPhotoUrl ();
79
+ }
45
80
}
0 commit comments