User.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App;
  3. use Illuminate\Notifications\Notifiable;
  4. use Illuminate\Contracts\Auth\MustVerifyEmail;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. class User extends Authenticatable
  7. {
  8. use Notifiable;
  9. /**
  10. * The attributes that are mass assignable.
  11. *
  12. * @var array
  13. */
  14. protected $fillable = [
  15. 'name', 'email', 'telegram_id', 'google_id', 'role_id', 'password',
  16. ];
  17. /**
  18. * The attributes that should be hidden for arrays.
  19. *
  20. * @var array
  21. */
  22. protected $hidden = [
  23. 'password', 'remember_token',
  24. ];
  25. /**
  26. * The attributes that should be cast to native types.
  27. *
  28. * @var array
  29. */
  30. protected $casts = [
  31. 'email_verified_at' => 'datetime',
  32. ];
  33. public function roles(){
  34. return $this->belongsTo(Role::class);
  35. }
  36. public function locations(){
  37. return $this->hasMany(Location::class);
  38. }
  39. public function groups(){
  40. return $this->belongsToMany(Group::class);
  41. }
  42. public function getLastCoordinatesAttribute(){
  43. return self::locations()->orderBy('created_at', 'desc')->first();
  44. }
  45. }