datatable.directory codebase https://datatable.directory/
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.
datatable.directory/app/Models/Table.php

94 lines
2.4 KiB

<?php
namespace App\Models;
use App\Models\Concerns\ManyManyThrough;
use App\Models\Concerns\Reportable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Riesjart\Relaquent\Model\Concerns\HasRelaquentRelationships;
/**
* A data table object (referencing revisions)
*
* @property int $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property int $owner_id
* @property int $ancestor_id
* @property int $revision_id
6 years ago
* @property string $name
* @property string $title
* @property string $description
* @property string $license
6 years ago
* @property string $origin
* @property-read User $owner
* @property-read Table $parentTable
* @property-read Table[]|Collection $forks
* @property-read Revision[]|Collection $revisions
* @property-read Revision $revision
* @property-read Proposal[]|Collection $proposal
* @property-read TableComment[]|Collection $comments
* @property-read User[]|Collection $favouritingUsers
* @property-read User[]|Collection $discussionFollowers
*/
6 years ago
class Table extends Model
{
use Reportable;
6 years ago
protected $guarded = [];
/** Owning user */
public function owner()
{
return $this->belongsTo(User::class, 'owner_id');
}
/** Fork precursor */
public function parentTable()
{
6 years ago
return $this->belongsTo(Table::class, 'ancestor_id');
}
/** Fork descendants */
public function forks()
{
6 years ago
return $this->hasMany(Table::class, 'ancestor_id');
}
/** All related revisions (this may include merged revisions) */
public function revisions()
{
return $this->belongsToMany(Revision::class, 'table_revision_pivot');
}
6 years ago
/** Active revision */
public function revision()
{
return $this->belongsTo(Revision::class, 'revision_id');
}
6 years ago
/** Proposals submitted to this table */
public function proposals()
{
6 years ago
return $this->hasMany(Proposal::class);
}
/** User-submitted comments */
public function comments()
{
return $this->hasMany(TableComment::class);
}
/** Users favouriting this table */
public function favouritingUsers()
{
return $this->belongsToMany(User::class, 'table_favourites');
}
/** Users to notify about comments */
public function discussionFollowers()
{
return $this->belongsToMany(User::class, 'discussion_follows');
}
}