mercredi 2 novembre 2022

Store data in database while checkbox in foreachloop using laravel

I want to store checkbox values in database while the checkbox in foreach loop. Other database columns have single value while the checkbox may have multiple. Class and section have same value but it only save 1 index value. I tried something like that in my controller.

foreach ($request['asn_sub_id'] as $key => $val) 
            {
                if (!empty($val))
                {
                    $ans = new TblAssignSubject();
                    $ans->asn_class_id = $request['asn_class_id'][$key];
                    $ans->asn_sec_id = $request['asn_sec_id'][$key];
                    $ans->asn_sub_id = $val;
                    $ans->asn_user_id = Auth::user()->id;
                    $ans->asn_status = 'Y';
                    $ans->save();
                }
            }
            return response()->json(["status"=>200]);



Aucun commentaire:

Enregistrer un commentaire