Skip to content

Commit fd5353a

Browse files
committed
Check if the custom field still exists
1 parent cc23cc9 commit fd5353a

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

resources/views/fields/partials/model.blade.php

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,53 @@
55
$fields = \VentureDrake\LaravelCrm\Models\FieldModel::where('model', get_class($model))->get();
66
}
77
@endphp
8-
@foreach($fields as $fieldValueOrModel)
9-
@switch($fieldValueOrModel->field->type)
10-
@case('text')
11-
@include('laravel-crm::partials.form.text',[
12-
'name' => 'fields['.$fieldValueOrModel->field->id.']',
13-
'label' => ucfirst(__($fieldValueOrModel->field->name)),
14-
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
15-
])
16-
@break
17-
@case('textarea')
18-
@include('laravel-crm::partials.form.textarea',[
19-
'name' => 'fields['.$fieldValueOrModel->field->id.']',
20-
'label' => ucfirst(__($fieldValueOrModel->field->name)),
21-
'rows' => 5,
22-
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
23-
])
24-
@break
25-
@case('select')
26-
@include('laravel-crm::partials.form.select',[
27-
'name' => 'fields['.$fieldValueOrModel->field->id.']',
28-
'label' => ucfirst(__($fieldValueOrModel->field->name)),
29-
'options' => ['' => ''] + $fieldValueOrModel->field->fieldOptions->pluck('label','id')->toArray(),
30-
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
31-
])
32-
@break
33-
@case('checkbox')
34-
@include('laravel-crm::partials.form.checkbox',[
35-
'name' => 'fields['.$fieldValueOrModel->field->id.']',
36-
'label' => ucfirst(__($fieldValueOrModel->field->name)),
37-
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
38-
])
39-
@break
40-
@case('checkbox_multiple')
41-
<x-form-group label="{{ ucfirst(__($fieldValueOrModel->field->name)) }}">
42-
@foreach($fieldValueOrModel->field->fieldOptions as $fieldOption)
43-
<x-form-checkbox name="fields[{{ $fieldValueOrModel->field->id }}]" value="{{ $fieldOption->id }}" label="{{ $fieldOption->label }}" />
44-
@endforeach
45-
</x-form-group>
46-
@break
47-
@case('radio')
48-
<x-form-group name="fields[{{ $fieldValueOrModel->field->id }}]" label="{{ ucfirst(__($fieldValueOrModel->field->name)) }}">
49-
@foreach($fieldValueOrModel->field->fieldOptions as $fieldOption)
50-
<x-form-radio name="fields[{{ $fieldValueOrModel->field->id }}]" value="{{ $fieldOption->id }}" label="{{ $fieldOption->label }}" />
51-
@endforeach
52-
</x-form-group>
53-
@break
54-
@endswitch
8+
@foreach($fields as $fieldValueOrModel)
9+
@if($fieldValueOrModel->field)
10+
@switch($fieldValueOrModel->field->type)
11+
@case('text')
12+
@include('laravel-crm::partials.form.text',[
13+
'name' => 'fields['.$fieldValueOrModel->field->id.']',
14+
'label' => ucfirst(__($fieldValueOrModel->field->name)),
15+
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
16+
])
17+
@break
18+
@case('textarea')
19+
@include('laravel-crm::partials.form.textarea',[
20+
'name' => 'fields['.$fieldValueOrModel->field->id.']',
21+
'label' => ucfirst(__($fieldValueOrModel->field->name)),
22+
'rows' => 5,
23+
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
24+
])
25+
@break
26+
@case('select')
27+
@include('laravel-crm::partials.form.select',[
28+
'name' => 'fields['.$fieldValueOrModel->field->id.']',
29+
'label' => ucfirst(__($fieldValueOrModel->field->name)),
30+
'options' => ['' => ''] + $fieldValueOrModel->field->fieldOptions->pluck('label','id')->toArray(),
31+
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
32+
])
33+
@break
34+
@case('checkbox')
35+
@include('laravel-crm::partials.form.checkbox',[
36+
'name' => 'fields['.$fieldValueOrModel->field->id.']',
37+
'label' => ucfirst(__($fieldValueOrModel->field->name)),
38+
'value' => old('fields['.$fieldValueOrModel->field->id.']', $fieldValueOrModel->value ?? null)
39+
])
40+
@break
41+
@case('checkbox_multiple')
42+
<x-form-group label="{{ ucfirst(__($fieldValueOrModel->field->name)) }}">
43+
@foreach($fieldValueOrModel->field->fieldOptions as $fieldOption)
44+
<x-form-checkbox name="fields[{{ $fieldValueOrModel->field->id }}]" value="{{ $fieldOption->id }}" label="{{ $fieldOption->label }}" />
45+
@endforeach
46+
</x-form-group>
47+
@break
48+
@case('radio')
49+
<x-form-group name="fields[{{ $fieldValueOrModel->field->id }}]" label="{{ ucfirst(__($fieldValueOrModel->field->name)) }}">
50+
@foreach($fieldValueOrModel->field->fieldOptions as $fieldOption)
51+
<x-form-radio name="fields[{{ $fieldValueOrModel->field->id }}]" value="{{ $fieldOption->id }}" label="{{ $fieldOption->label }}" />
52+
@endforeach
53+
</x-form-group>
54+
@break
55+
@endswitch
56+
@endif
5557
@endforeach

0 commit comments

Comments
 (0)