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/Proposal.php

62 lines
1.3 KiB

6 years ago
<?php
namespace App\Models;
use App\Models\Concerns\Reportable;
6 years ago
use Illuminate\Database\Eloquent\Model;
/**
* Change proposal
*
* @property int $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property int $table_id
* @property int $revision_id
* @property int $author_id
* @property string $note
* @property User $author
* @property Table $table
* @property Revision $revision
* @property object $changes - JSONB
6 years ago
*/
class Proposal extends Model
{
use Reportable;
6 years ago
protected $guarded = [];
protected static function boot()
{
parent::boot();
static::deleting(function(Proposal $self) {
$self->reportsOf()->delete();
// update refcounts
$rev = $self->revision;
$rev->decrement('refs');
// Delete the revision if it has no other refs (manually, to update row refs)
if ($rev->refs <= 0) $rev->delete();
});
}
6 years ago
/** Authoring user */
public function author()
{
return $this->belongsTo(User::class, 'author_id');
}
/** Target revision */
public function revision()
{
return $this->belongsTo(Revision::class);
}
/** Target table (that this was submitted to) */
public function table()
{
return $this->belongsTo(Table::class);
}
}