Add Paste and Deletion models

This commit is contained in:
Les De Ridder 2016-05-28 22:43:44 +02:00
parent 617b9a9bf0
commit 30eff3455e
2 changed files with 35 additions and 2 deletions

View File

@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Deletion extends Model
{
//
public $timestamps = false;
public function paste()
{
return $this->belongsTo(Paste::class);
}
}

View File

@ -6,5 +6,33 @@ use Illuminate\Database\Eloquent\Model;
class Paste extends Model
{
//
public $incrementing = false;
public $timestamps = false;
public function deletion()
{
return $this->hasOne(Deletion::class);
}
public function isDeleted()
{
return $this->deletion !== null;
}
public function delete($reason, $deleted_by)
{
if($this->isDeleted())
{
return false;
}
$deletion = new Deletion;
$deletion->reason = $reason;
$deletion->deleted_by = $deleted_by;
$deletion->deleted_at = Carbon::now();
$this->deletion()->save($deletion);
return true;
}
}