tethys/app/Models/Person.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2018-08-29 15:18:15 +00:00
<?php
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',
'last_name',
'first_name',
'email',
'identifier_orcid',
2018-09-10 13:09:10 +00:00
'status',
2018-08-06 12:30:51 +00:00
];
protected $table = 'persons';
2018-09-10 13:09:10 +00:00
public $timestamps = false;
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')
->withPivot('role');
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
{
return $this->first_name . " " . $this->last_name;
}
public function scopeActive($query)
{
return $query->where('status', 1);
}
public function scopeOrderByName($query)
{
return $query->orderBy('last_name');
}
}