2018-08-29 15:18:15 +00:00
|
|
|
<?php
|
2022-08-05 11:26:42 +00:00
|
|
|
|
2018-09-10 13:09:10 +00:00
|
|
|
namespace App\Models;
|
2018-08-06 12:30:51 +00:00
|
|
|
|
2018-09-10 13:09:10 +00:00
|
|
|
use App\Models\Dataset;
|
2018-08-06 12:30:51 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Person extends Model
|
|
|
|
{
|
|
|
|
protected $fillable = [
|
|
|
|
'academic_title',
|
2018-10-19 10:54:40 +00:00
|
|
|
'date_of_birth',
|
2018-08-06 12:30:51 +00:00
|
|
|
'last_name',
|
|
|
|
'first_name',
|
|
|
|
'email',
|
|
|
|
'identifier_orcid',
|
2018-09-10 13:09:10 +00:00
|
|
|
'status',
|
2022-08-05 11:26:42 +00:00
|
|
|
'name_type',
|
2018-08-06 12:30:51 +00:00
|
|
|
];
|
2022-08-05 11:26:42 +00:00
|
|
|
|
2018-08-06 12:30:51 +00:00
|
|
|
protected $table = 'persons';
|
2022-08-05 11:26:42 +00:00
|
|
|
|
2018-09-10 13:09:10 +00:00
|
|
|
public $timestamps = false;
|
2022-08-05 11:26:42 +00:00
|
|
|
|
2018-09-10 13:09:10 +00:00
|
|
|
protected $appends = ['full_name'];
|
2018-08-06 12:30:51 +00:00
|
|
|
|
|
|
|
public function documents()
|
|
|
|
{
|
2018-09-10 13:09:10 +00:00
|
|
|
return $this->belongsToMany(Dataset::class, 'link_documents_persons', 'person_id', 'document_id')
|
2019-09-16 11:47:30 +00:00
|
|
|
->withPivot('role', 'sort_order', 'allow_email_contact');
|
2018-08-06 12:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// public function scopeNotLimit($query)
|
|
|
|
// {
|
|
|
|
// return $query->where('borrow', '<', 3);
|
|
|
|
// }
|
2018-09-10 13:09:10 +00:00
|
|
|
|
2018-08-06 12:30:51 +00:00
|
|
|
/**
|
|
|
|
* Get the user's full name.
|
2018-09-10 13:09:10 +00:00
|
|
|
* see https://laravel.com/docs/5.6/eloquent-serialization
|
2018-08-06 12:30:51 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-09-10 13:09:10 +00:00
|
|
|
public function getFullNameAttribute()
|
2018-08-06 12:30:51 +00:00
|
|
|
{
|
2022-08-05 11:26:42 +00:00
|
|
|
return $this->first_name.' '.$this->last_name.' '.$this->date_of_birth;
|
2018-08-06 12:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeActive($query)
|
|
|
|
{
|
|
|
|
return $query->where('status', 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeOrderByName($query)
|
|
|
|
{
|
|
|
|
return $query->orderBy('last_name');
|
|
|
|
}
|
|
|
|
}
|