User.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Illuminate\Notifications\Notifiable;
  7. use Laravel\Sanctum\HasApiTokens;
  8. class User extends Authenticatable
  9. {
  10. use HasApiTokens, HasFactory, Notifiable;
  11. /**
  12. * The attributes that are mass assignable.
  13. *
  14. * @var array<int, string>
  15. */
  16. protected $fillable = [
  17. 'name',
  18. 'email',
  19. 'password',
  20. ];
  21. /**
  22. * The attributes that should be hidden for serialization.
  23. *
  24. * @var array<int, string>
  25. */
  26. protected $hidden = [
  27. 'password',
  28. 'remember_token',
  29. ];
  30. /**
  31. * The attributes that should be cast.
  32. *
  33. * @var array<string, string>
  34. */
  35. protected $casts = [
  36. 'email_verified_at' => 'datetime',
  37. ];
  38. public function comments() {
  39. return $this->hasMany(Comment::class, 'user');
  40. }
  41. public function films() {
  42. return $this->hasMany(Film::class, 'user');
  43. }
  44. public function votes() {
  45. return $this->hasMany(Vote::class, 'user');
  46. }
  47. public function settings() {
  48. return $this->hasMany(Setting::class, 'user');
  49. }
  50. public function news() {
  51. return $this->hasMany(News::class, 'user');
  52. }
  53. public function getAvatar() {
  54. $settings = $this->settings()->where('key', '=', 'avatar')->first();
  55. return is_null($settings) ? "no-avatar.jpg" : $settings->value;
  56. }
  57. public function isActive() {
  58. return !$this->disabled;
  59. }
  60. public function isAdmin() {
  61. $settings = $this->settings()->where('key', '=', 'admin')->first();
  62. return !is_null($settings);
  63. }
  64. }