Skip to content

Commit 2996075

Browse files
committed
Add support for archived_at field
1 parent 2de2fba commit 2996075

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

database/migrations/create_custom_fields_tables.php.stub

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class CreateCustomFieldsTables extends Migration
2525
$table->string('default_value')->nullable();
2626
$table->string('order');
2727
$table->timestamps();
28-
$table->timestamp('deleted_at')->nullable();
28+
$table->timestamp('archived_at')->nullable();
29+
$table->softDeletes();
2930
});
3031

3132
Schema::create(config('custom-fields.tables.field_responses', 'custom_field_responses'), function (Blueprint $table) {

src/Models/CustomField.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CustomField extends Model
7272
*/
7373
protected $casts = [
7474
'answers' => 'array',
75+
'archived_at' => 'datetime',
7576
];
7677

7778
/**
@@ -96,7 +97,8 @@ protected static function boot()
9697
parent::boot();
9798

9899
self::creating(function ($field) {
99-
$lastFieldOnCurrentModel = $field->model->customFields()->orderBy('order', 'desc')->first();
100+
$lastFieldOnCurrentModel = $field->model->customFields()->orderByDesc('order')->first();
101+
100102
$field->order = ($lastFieldOnCurrentModel ? $lastFieldOnCurrentModel->order : 0) + 1;
101103
});
102104
}

src/Models/CustomFieldResponse.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ class CustomFieldResponse extends Model
4343
*/
4444
public function __construct(array $attributes = [])
4545
{
46-
// We have to do this because the `value` mutator depends on
47-
// `field_id` being set. If `value` is declared earlie than `field_id`
48-
// in a create() array, the mutator will blow up.
46+
/*
47+
* We have to do this because the `value` mutator
48+
* depends on `field_id` being set. If `value`
49+
* is declared earlier than `field_id` in a
50+
* create() array, the mutator will fail.
51+
*/
52+
4953
$this->attributes = $attributes;
5054

5155
$this->bootIfNotBooted();

0 commit comments

Comments
 (0)