Fix removed properties casting

This commit is contained in:
Julien Nahum 2023-10-13 11:43:53 +02:00
parent 2ab3f79801
commit f0939f3992
2 changed files with 9 additions and 5 deletions

View File

@ -37,7 +37,7 @@ class FormController extends Controller
$forms = $workspace->forms()->with(['creator','views','submissions']) $forms = $workspace->forms()->with(['creator','views','submissions'])
->orderByDesc('updated_at') ->orderByDesc('updated_at')
->paginate(10)->through(function (Form $form) use ($workspace, $workspaceIsPro){ ->paginate(10)->through(function (Form $form) use ($workspace, $workspaceIsPro){
// Add attributes for faster loading // Add attributes for faster loading
$form->extra = (object) [ $form->extra = (object) [
'loadedWorkspace' => $workspace, 'loadedWorkspace' => $workspace,
@ -113,7 +113,7 @@ class FormController extends Controller
->processRequest($request) ->processRequest($request)
->simulateCleaning($form->workspace) ->simulateCleaning($form->workspace)
->getData(); ->getData();
// Set Removed Properties // Set Removed Properties
$formData['removed_properties'] = array_merge($form->removed_properties, collect($form->properties)->filter(function ($field) use ($formData) { $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())); return (!Str::of($field['type'])->startsWith('nf-') && !in_array($field['id'], collect($formData['properties'])->pluck("id")->toArray()));

View File

@ -15,6 +15,7 @@ use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions; use Spatie\Sluggable\SlugOptions;
use Stevebauman\Purify\Facades\Purify; use Stevebauman\Purify\Facades\Purify;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Casts\Attribute;
class Form extends Model class Form extends Model
{ {
@ -218,9 +219,12 @@ class Form extends Model
return !empty($this->password); return !empty($this->password);
} }
public function getRemovedPropertiesAttribute() protected function removedProperties(): Attribute {
{ return Attribute::make(
return $this->attributes['removed_properties'] ?? []; get: function ($value) {
return $value ? json_decode($value, true) : [];
}
);
} }
/** /**