better collection handlich in backend
This commit is contained in:
parent
324eacf061
commit
50bcae442e
24 changed files with 623 additions and 68 deletions
|
@ -7,9 +7,34 @@ use App\Models\Dataset;
|
|||
|
||||
class Collection extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'role_id',
|
||||
];
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->belongsToMany(Dataset::class, 'link_documents_collections', 'collection_id', 'document_id');
|
||||
}
|
||||
|
||||
#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');
|
||||
}
|
||||
}
|
||||
|
|
29
app/Models/CollectionRole.php
Normal file
29
app/Models/CollectionRole.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Collection;
|
||||
use App\Models\Dataset;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CollectionRole extends Model
|
||||
{
|
||||
protected $table = 'collections_roles';
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'oai_name',
|
||||
'visible',
|
||||
];
|
||||
|
||||
// public function documents()
|
||||
// {
|
||||
// return $this->belongsToMany(Dataset::class, 'link_documents_collections', 'role_id', 'document_id');
|
||||
// }
|
||||
|
||||
public function collections()
|
||||
{
|
||||
//model, foreign key on the Collection model is role_id, local id of this is id
|
||||
return $this->hasMany(Collection::class, 'role_id', 'id');
|
||||
}
|
||||
}
|
|
@ -62,6 +62,12 @@ class Dataset extends Model
|
|||
->belongsToMany(Collection::class, 'link_documents_collections', 'document_id', 'collection_id');
|
||||
}
|
||||
|
||||
// public function collectionRoles()
|
||||
// {
|
||||
// return $this
|
||||
// ->belongsToMany(CollectionRole::class, 'link_documents_collections', 'document_id', 'role_id');
|
||||
// }
|
||||
|
||||
#region [person table]
|
||||
|
||||
//return all persons attached to this film
|
||||
|
|
|
@ -12,7 +12,7 @@ class Project extends Model
|
|||
// for using $input = $request->all();
|
||||
//$project = Project::create($input);
|
||||
protected $fillable = [
|
||||
'name', 'label'
|
||||
'name', 'label', 'description'
|
||||
];
|
||||
|
||||
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue