User.php 684 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Tests\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class User extends Model
  5. {
  6. protected $table = 'test_users';
  7. protected $appends = ['full_name', 'position'];
  8. public function profile()
  9. {
  10. return $this->hasOne(Profile::class, 'user_id');
  11. }
  12. public function getFullNameAttribute()
  13. {
  14. return "{$this->profile['first_name']} {$this->profile['last_name']}";
  15. }
  16. public function getPositionAttribute()
  17. {
  18. return "{$this->profile->latitude} {$this->profile->longitude}";
  19. }
  20. public function tags()
  21. {
  22. return $this->belongsToMany(Tag::class, 'test_user_tags', 'user_id', 'tag_id');
  23. }
  24. }