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'])
->orderByDesc('updated_at')
->paginate(10)->through(function (Form $form) use ($workspace, $workspaceIsPro){
// Add attributes for faster loading
$form->extra = (object) [
'loadedWorkspace' => $workspace,
@ -113,7 +113,7 @@ class FormController extends Controller
->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()));

View File

@ -15,6 +15,7 @@ use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Stevebauman\Purify\Facades\Purify;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Casts\Attribute;
class Form extends Model
{
@ -218,9 +219,12 @@ class Form extends Model
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) : [];
}
);
}
/**