Add Paste and Deletion models
This commit is contained in:
parent
617b9a9bf0
commit
30eff3455e
|
@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Deletion extends Model
|
||||
{
|
||||
//
|
||||
public $timestamps = false;
|
||||
|
||||
public function paste()
|
||||
{
|
||||
return $this->belongsTo(Paste::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue