tethys/app/Models/Collection.php

46 lines
946 B
PHP
Raw Normal View History

2018-09-10 13:09:10 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2018-09-10 13:09:10 +00:00
use App\Models\Dataset;
class Collection extends Model
{
use HasFactory;
2018-10-04 14:41:29 +00:00
public $timestamps = false;
2018-10-10 16:28:51 +00:00
//mass assignable
2018-10-04 14:41:29 +00:00
protected $fillable = [
'name',
2018-10-10 16:28:51 +00:00
'number',
2018-10-04 14:41:29 +00:00
'role_id',
];
2018-09-10 13:09:10 +00:00
public function documents()
{
return $this->belongsToMany(Dataset::class, 'link_documents_collections', 'collection_id', 'document_id');
}
2018-10-04 14:41:29 +00:00
#region self join
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
#endregion
/**
* Get the collection role that the dataset belongs to.
*/
public function collectionrole()
{
return $this->belongsTo(CollectionRole::class, 'role_id', 'id');
}
2018-09-10 13:09:10 +00:00
}