forms - In Laravel using the old helper, how to check value of old('value', 'default') when 'value' is an array and 'default' is a basic value? -


say have checkboxes. each value goes array when checked.

<input type="checkbox" id="card_type1" name="card_type[]" value="easy" @if(old('card_type') != null && in_array('easy', old('card_type')) || old('foo', $parkinglot->m_plots_can_easycard) === '1') checked @endif> <input type="checkbox" id="card_type2" name="card_type[]" value="icash" @if(old('card_type') != null && in_array('icash', old('card_type')) || old('foo', $parkinglot->m_plots_can_icash20) === '1') checked @endif> <input type="checkbox" id="card_type3" name="card_type[]" value="ipass" @if(old('card_type') != null && in_array('ipass', old('card_type')) || old('foo', $parkinglot->m_plots_can_ipass) === '1') checked @endif> 

upon loading form first time, want reflect database value. if value in db '1', check checkbox. modify checkboxes - checking , unchecking - , submit form , form submission fails. want reflect old values checking whether each value in old checkbox array, checking checkboxes if so.

my problem old('value', 'default') consists of both 'value' , 'default' , can't use separate methods determine whether checkbox should checked. , if (as in above), can't have old('default') - , separate check there - because having 1 parameter makes old('value').

i'm not sure how go in situation. pointers or appreciated. hope illustrated clear enough situation is.

you may try following

<input type="checkbox" id="card_type1" name="card_type[]" value="easy"      @if (in_array('easy', old('card_type', [$parkinglot->m_plots_can_easycard === '1' ? 'easy' : ''])))          checked      @endif> <input type="checkbox" id="card_type2" name="card_type[]" value="icash"      @if (in_array('icash', old('card_type', [$parkinglot->m_plots_can_icash20 === '1' ? 'icash' : ''])))          checked      @endif> <input type="checkbox" id="card_type3" name="card_type[]" value="ipass"      @if (in_array('ipass', old('card_type', [$parkinglot->m_plots_can_ipass === '1' ? 'ipass' : ''])))          checked      @endif> 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -