1 | <?php |
||
15 | class User extends Authenticatable |
||
16 | { |
||
17 | use Notifiable; |
||
18 | |||
19 | /** |
||
20 | * The preferences that we don't want to show to the client. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private const HIDDEN_PREFERENCES = ['lastfm_session_key']; |
||
25 | |||
26 | protected $guarded = ['id']; |
||
27 | protected $casts = [ |
||
28 | 'id' => 'int', |
||
29 | 'is_admin' => 'bool', |
||
30 | ]; |
||
31 | protected $hidden = ['password', 'remember_token', 'created_at', 'updated_at']; |
||
32 | |||
33 | public function playlists(): HasMany |
||
37 | |||
38 | public function interactions(): HasMany |
||
42 | |||
43 | /** |
||
44 | * @return mixed|null |
||
45 | */ |
||
46 | public function getPreference(string $key) |
||
52 | |||
53 | /** |
||
54 | * @param mixed $val |
||
55 | */ |
||
56 | public function savePreference(string $key, $val): void |
||
64 | |||
65 | /** |
||
66 | * An alias to savePreference(). |
||
67 | * |
||
68 | * @param mixed $val |
||
69 | * |
||
70 | * @see self::savePreference |
||
71 | */ |
||
72 | public function setPreference(string $key, $val): void |
||
76 | |||
77 | public function deletePreference(string $key): void |
||
84 | |||
85 | /** |
||
86 | * Determine if the user is connected to Last.fm. |
||
87 | */ |
||
88 | public function connectedToLastfm(): bool |
||
92 | 4 | ||
93 | /** |
||
94 | 4 | * Get the user's Last.fm session key. |
|
95 | 4 | * |
|
96 | 4 | * @return string|null The key if found, or null if user isn't connected to Last.fm |
|
97 | */ |
||
98 | 4 | public function getLastfmSessionKeyAttribute(): ?string |
|
102 | |||
103 | /** |
||
104 | * User preferences are stored as a serialized associative array. |
||
105 | * |
||
106 | * @param mixed[] $value |
||
107 | */ |
||
108 | public function setPreferencesAttribute(array $value): void |
||
112 | |||
113 | /** |
||
114 | * Unserialize the user preferences back to an array before returning. |
||
115 | * |
||
116 | * @return mixed[] |
||
117 | */ |
||
118 | public function getPreferencesAttribute(?string $value): array |
||
131 | } |
||
132 |