Skip to content

Commit fbad4b3

Browse files
committed
Add archive() and unarchive() methods to CustomField model
1 parent 2996075 commit fbad4b3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Models/CustomField.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Givebutter\LaravelCustomFields\Models;
44

5+
use Carbon\Carbon;
56
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -123,6 +124,34 @@ public function responses()
123124
return $this->hasMany(CustomFieldResponse::class, 'field_id');
124125
}
125126

127+
/**
128+
* Archive the model.
129+
*
130+
* @return $this
131+
*/
132+
public function archive()
133+
{
134+
$this->forceFill([
135+
'archived_at' => now(),
136+
])->save();
137+
138+
return $this;
139+
}
140+
141+
/**
142+
* Unarchive the model.
143+
*
144+
* @return $this
145+
*/
146+
public function unarchive()
147+
{
148+
$this->forceFill([
149+
'archived_at' => null,
150+
])->save();
151+
152+
return $this;
153+
}
154+
126155
/**
127156
* Get the validation rules attribute.
128157
*

0 commit comments

Comments
 (0)