refactor: ♻️ Use Switch state instead of elseif

This commit is contained in:
IceToast 2023-02-09 22:38:47 +01:00 committed by IceToast
parent ac5fa6c25c
commit 20f0e1dfc2

View file

@ -83,16 +83,23 @@
<i class="fas fa-info-circle mr-4 invisible"></i> <i class="fas fa-info-circle mr-4 invisible"></i>
@endif @endif
@if ($value['type'] == 'string') @switch($value)
@case($value['type'] == 'string')
<input type="text" class="form-control" <input type="text" class="form-control"
name="{{ $key }}" value="{{ $value['value'] }}"> name="{{ $key }}" value="{{ $value['value'] }}">
@elseif ($value['type'] == 'boolean') @break
@case($value['type'] == 'boolean')
<input type="checkbox" name="{{ $key }}" <input type="checkbox" name="{{ $key }}"
value="{{ $value['value'] }}"> value="{{ $value['value'] }}">
@elseif ($value['type'] == 'number') @break
@case($value['type'] == 'number')
<input type="number" class="form-control" <input type="number" class="form-control"
name="{{ $key }}" value="{{ $value['value'] }}"> name="{{ $key }}" value="{{ $value['value'] }}">
@elseif ($value['type'] == 'select') @break
@case($value['type'] == 'select')
<select id="{{ $key }}" class="custom-select w-100" <select id="{{ $key }}" class="custom-select w-100"
name="{{ $key }}"> name="{{ $key }}">
@foreach ($value['options'] as $option) @foreach ($value['options'] as $option)
@ -102,9 +109,11 @@
</option> </option>
@endforeach @endforeach
</select> </select>
@elseif($value['type'] == 'multiselect') @break
<select class="custom-select w-100" name="{{ $key }}"
multiple> @case($value['type'] == 'multiselect')
<select id="{{ $key }}" class="custom-select w-100"
name="{{ $key }}" multiple>
@foreach ($value['options'] as $option) @foreach ($value['options'] as $option)
<option value="{{ $option }}" <option value="{{ $option }}"
{{ $value['value'] == $option ? 'selected' : '' }}> {{ $value['value'] == $option ? 'selected' : '' }}>
@ -112,9 +121,14 @@
</option> </option>
@endforeach @endforeach
</select> </select>
@elseif($value['type'] == 'textarea') @break
<textarea class="form-control w-100" name="{{ $key }}" rows="3">{{ $value['value'] }}</textarea>
@endif @case($value['type'] == 'textarea')
<textarea class="form-control" name="{{ $key }}" rows="3">{{ $value['value'] }}</textarea>
@break
@default
@endswitch
</div> </div>
</div> </div>