User.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. use Illuminate\Auth\UserInterface;
  3. use Illuminate\Auth\Reminders\RemindableInterface;
  4. class User extends Eloquent implements UserInterface, RemindableInterface {
  5. /**
  6. * The database table used by the model.
  7. *
  8. * @var string
  9. */
  10. protected $table = 'users';
  11. protected $softDelete = true;
  12. /**
  13. * The attributes excluded from the model's JSON form.
  14. *
  15. * @var array
  16. */
  17. protected $hidden = array('password');
  18. /**
  19. * Get the unique identifier for the user.
  20. *
  21. * @return mixed
  22. */
  23. public function getAuthIdentifier()
  24. {
  25. return $this->getKey();
  26. }
  27. /**
  28. * Get the password for the user.
  29. *
  30. * @return string
  31. */
  32. public function getAuthPassword()
  33. {
  34. return $this->password;
  35. }
  36. /**
  37. * Get the e-mail address where password reminders are sent.
  38. *
  39. * @return string
  40. */
  41. public function getReminderEmail()
  42. {
  43. return $this->email;
  44. }
  45. public function getAvatar() {
  46. if($avatar = $this->getSetting('avatar')) {
  47. return asset('img/avatars/'.$avatar);
  48. } else {
  49. return asset('img/no-avatar.jpg');
  50. }
  51. }
  52. public function getSetting($key, $false = false) {
  53. $settings = json_decode($this->settings);
  54. if(!is_null($settings))
  55. return $settings->$key;
  56. else
  57. return $false;
  58. }
  59. public function setSetting($key, $value) {
  60. $settings = json_decode($this->settings);
  61. if(!is_null($settings)) {
  62. $settings = array();
  63. }
  64. $settings[$key] = $value;
  65. $this->settings = json_encode($settings);
  66. }
  67. public function films() {
  68. return $this->hasMany('Film', 'user');
  69. }
  70. public function comments() {
  71. return $this->hasMany('Comment', 'user');
  72. }
  73. public function votes() {
  74. return $this->hasMany('Vote', 'user');
  75. }
  76. public function news() {
  77. return $this->hasMany('News', 'author');
  78. }
  79. }