Skip to content

Commit

Permalink
Fix removed properties casting
Browse files Browse the repository at this point in the history
  • Loading branch information
JhumanJ committed Oct 13, 2023
1 parent 2ab3f79 commit f0939f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Forms/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function index($workspaceId)
$forms = $workspace->forms()->with(['creator','views','submissions'])
->orderByDesc('updated_at')
->paginate(10)->through(function (Form $form) use ($workspace, $workspaceIsPro){

// Add attributes for faster loading
$form->extra = (object) [
'loadedWorkspace' => $workspace,
Expand Down Expand Up @@ -113,7 +113,7 @@ public function update(UpdateFormRequest $request, string $id)
->processRequest($request)
->simulateCleaning($form->workspace)
->getData();

// Set Removed Properties
$formData['removed_properties'] = array_merge($form->removed_properties, collect($form->properties)->filter(function ($field) use ($formData) {
return (!Str::of($field['type'])->startsWith('nf-') && !in_array($field['id'], collect($formData['properties'])->pluck("id")->toArray()));
Expand Down
10 changes: 7 additions & 3 deletions app/Models/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Spatie\Sluggable\SlugOptions;
use Stevebauman\Purify\Facades\Purify;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Casts\Attribute;

class Form extends Model
{
Expand Down Expand Up @@ -218,9 +219,12 @@ public function getHasPasswordAttribute()
return !empty($this->password);
}

public function getRemovedPropertiesAttribute()
{
return $this->attributes['removed_properties'] ?? [];
protected function removedProperties(): Attribute {
return Attribute::make(
get: function ($value) {
return $value ? json_decode($value, true) : [];
}
);
}

/**
Expand Down

0 comments on commit f0939f3

Please sign in to comment.