I'm trying to understand why my checkboxes are not being submitted as a user_id array, can anyone help me figure out why? I'm obviously doing something wrong but I can't figure it out.
// View
{{ Form::model($process, array('route' => array('judi.processes.update', $process->id), 'method' => 'put') ) }}
@foreach ($assessors->users as $assessor)
{{ Form::checkbox( 'user_id[]', $assessor->id, checkboxState( $assessor->id, $process->users()->lists('user_id') ) ) }}
@endforeach
{{ Form::submit('Submit') }}
{{ Form::close() }}
// Controller
$users = Input::get('user_id');
// Output
Users
[
0 =>'1'
1 =>'106'
2 =>'107'
]
// Looking for
Users
'user_id' = [
0 => '1',
1 => '106',
2 => '107'
]
Thanks
There's some weird functionality when using Input::get()
, where if you only get one thing, it returns it as an array; in your case:
array(3) { [0] =>'1', [1] =>'106', [2] =>'107'] }
Try changing Input::get('user_id')
to:
$users = Input::only('user_id');
And check the results. It should now be formatted as:
array(1) { ['user_id'] => array(3) { [0] => '1', [1] => '106', [2] => '107'] } }
Let me know if that works!
I think since you are using Input::get('user_id')
, it is the desired behavior.
To get what you are looking for, I guess you should use Input::all()