You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1019 B
50 lines
1019 B
<?php |
|
|
|
namespace Tests\Models; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
class User extends Model |
|
{ |
|
protected $table = 'test_users'; |
|
|
|
protected $appends = ['full_name', 'position']; |
|
|
|
public function profile() |
|
{ |
|
return $this->hasOne(Profile::class, 'user_id'); |
|
} |
|
|
|
public function user_profile() |
|
{ |
|
return $this->hasOne(Profile::class, 'user_id'); |
|
} |
|
|
|
public function userProfile() |
|
{ |
|
return $this->hasOne(Profile::class, 'user_id'); |
|
} |
|
|
|
public function getFullNameAttribute() |
|
{ |
|
if (! $this->profile) { |
|
return; |
|
} |
|
|
|
return "{$this->profile['first_name']} {$this->profile['last_name']}"; |
|
} |
|
|
|
public function getPositionAttribute() |
|
{ |
|
if (! $this->profile) { |
|
return; |
|
} |
|
|
|
return "{$this->profile->latitude} {$this->profile->longitude}"; |
|
} |
|
|
|
public function tags() |
|
{ |
|
return $this->belongsToMany(Tag::class, 'test_user_tags', 'user_id', 'tag_id'); |
|
} |
|
}
|
|
|