Monday 15 February 2010

loops - Looping on checkbox array values inside Laravel Controller is not working -



loops - Looping on checkbox array values inside Laravel Controller is not working -

i have multiple checkboxes on form generated model view presented way:

{{form::open(array('action'=>'laboratorycontroller@store'))}} @foreach (accounts::where('accountclass',$i)->get() $accounttypes) {{ form::checkbox('accounttype[]', $accounttypes->id)}} @endforeach {{form::submit('save')}} {{form::close()}}

when homecoming input::all() controller store method, outputs this:

{"client":"1","accounttype":["2","3","5","12","13","14","16","31","32","33"]}

now want store accounttypes array values accounts table looping through array in order store each values on each rows using same client id.

the same accounttype inserted sec table different data.

so, accounts table:

+-------------+---------------------------+------+-----+---------+----------------+ | field | type | null | key | default | | +-------------+---------------------------+------+-----+---------+----------------+ | accountno | int(11) unsigned zerofill | no | pri | null | auto_increment | | accounttype | int(11) | no | | null | | | client | int(11) | no | | null | | | created_at | datetime | no | | null | | +-------------+---------------------------+------+-----+---------+----------------+

my controller store method:

public function store() { $accounttypes = input::get('accounttype'); if(is_array($accounttypes)) { for($i=0;$i < count($accounttypes);$i++) { // insert info on first table (accounts table) $accountno = db::table('accounts')->insertgetid(array('client'=>input::get('client'),'accounttype',$accounttypes[$i])); // insert info on sec table (account summary table) using business relationship no above // db::table('accountsummary')...blah blah } } homecoming redirect::to('some/path'); }

the function seems work first array value "2". don't know what's wrong code seems loop doesn't go through rest of values. testing other loop methods while , foreach still looping variable ($i) returns zero.

i thinking if laravel controller doesn't allow loops on post methods.

your inputs appreciated. thanks..

foreach , db::insert() works me.

foreach ($accounttypes $accounttype) { db::insert('insert tb_accounts (accounttype,client) values (?,?)', array($accounttype,input::get('client')); }

i need create separate query lastly insert id because db::insertgetid doesn't work way want it. that's issue. anyway, thanks.

arrays loops laravel checkbox controller

No comments:

Post a Comment