koel/app/Models/User.php

70 lines
1.7 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Models;
use App\Casts\UserPreferencesCast;
use App\Values\UserPreferences;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2017-08-05 17:44:38 +00:00
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder;
2015-12-27 09:12:10 +00:00
use Illuminate\Foundation\Auth\User as Authenticatable;
2016-09-26 06:30:00 +00:00
use Illuminate\Notifications\Notifiable;
2020-09-06 18:21:39 +00:00
use Laravel\Sanctum\HasApiTokens;
2015-12-13 04:42:28 +00:00
2016-02-03 15:39:15 +00:00
/**
* @property UserPreferences $preferences
* @property int $id
* @property bool $is_admin
2018-09-04 06:25:24 +00:00
* @property string $lastfm_session_key
* @property string $name
* @property string $email
* @property string $password
2019-08-05 10:57:36 +00:00
*
2019-08-05 10:56:48 +00:00
* @method static self create(array $params)
* @method static int count()
* @method static Builder where(...$params)
2016-02-03 15:39:15 +00:00
*/
2015-12-27 09:12:10 +00:00
class User extends Authenticatable
2015-12-13 04:42:28 +00:00
{
2020-09-06 18:21:39 +00:00
use HasApiTokens;
use HasFactory;
use Notifiable;
2016-09-26 06:30:00 +00:00
2015-12-13 04:42:28 +00:00
protected $guarded = ['id'];
protected $hidden = ['password', 'remember_token', 'created_at', 'updated_at'];
2015-12-13 04:42:28 +00:00
protected $casts = [
2015-12-15 10:32:41 +00:00
'id' => 'int',
2015-12-13 04:42:28 +00:00
'is_admin' => 'bool',
'preferences' => UserPreferencesCast::class,
2015-12-13 04:42:28 +00:00
];
2018-08-24 15:27:19 +00:00
public function playlists(): HasMany
2015-12-13 04:42:28 +00:00
{
return $this->hasMany(Playlist::class);
}
2018-08-24 15:27:19 +00:00
public function interactions(): HasMany
2015-12-13 04:42:28 +00:00
{
return $this->hasMany(Interaction::class);
}
2015-12-20 12:17:35 +00:00
2018-09-04 06:25:24 +00:00
/**
* Determine if the user is connected to Last.fm.
*/
public function connectedToLastfm(): bool
{
return (bool) $this->lastfm_session_key;
}
/**
* Get the user's Last.fm session key.
*
* @return string|null The key if found, or null if user isn't connected to Last.fm
*/
public function getLastfmSessionKeyAttribute(): ?string
{
return $this->preferences->lastFmSessionKey;
2015-12-20 12:17:35 +00:00
}
2015-12-13 04:42:28 +00:00
}