Browse Source

Add Paste and Deletion models

master
Les De Ridder 5 years ago
parent
commit
30eff3455e
2 changed files with 35 additions and 2 deletions
  1. +6
    -1
      app/Deletion.php
  2. +29
    -1
      app/Paste.php

+ 6
- 1
app/Deletion.php 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);
}
}

+ 29
- 1
app/Paste.php 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;
}
}

Loading…
Cancel
Save