87 lines
1.9 KiB
PHP
Executable File
87 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'username',
|
|
'email',
|
|
'password',
|
|
'avatar',
|
|
'role',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
// Relationships
|
|
public function videos()
|
|
{
|
|
return $this->hasMany(Video::class);
|
|
}
|
|
|
|
public function likes()
|
|
{
|
|
return $this->belongsToMany(Video::class, 'video_likes')->withTimestamps();
|
|
}
|
|
|
|
public function views()
|
|
{
|
|
return $this->belongsToMany(Video::class, 'video_views')->withTimestamps();
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->hasMany(Comment::class);
|
|
}
|
|
|
|
public function getAvatarUrlAttribute()
|
|
{
|
|
if ($this->avatar) {
|
|
return asset('storage/avatars/' . $this->avatar);
|
|
}
|
|
return 'https://i.pravatar.cc/150?u=' . $this->id;
|
|
}
|
|
|
|
// Role helper methods
|
|
public function isSuperAdmin()
|
|
{
|
|
return $this->role === 'super_admin';
|
|
}
|
|
|
|
public function isAdmin()
|
|
{
|
|
return in_array($this->role, ['admin', 'super_admin']);
|
|
}
|
|
|
|
public function isUser()
|
|
{
|
|
return $this->role === 'user' || $this->role === null;
|
|
}
|
|
|
|
// Placeholder for subscriber count (would need a separate table in full implementation)
|
|
public function getSubscriberCountAttribute()
|
|
{
|
|
// For now, return a placeholder - in production this would come from a subscriptions table
|
|
return rand(100, 10000);
|
|
}
|
|
}
|
|
|