'How do I insert an array as new row for each of the array item selected?

I have three tables group, record types and group record types. My form takes a multiple selection for the record types field and create an array or single value based on the user selection on the record type column in group table. However I want to insert these arrays as new single rows(each array to have new row) in group record table. How can it be done in Laravel? Below is my group controller store code.

    public function store(Store group Request $request)
{
    //
    $request->merge([
        'record type' => implode(',', (array) $request->get('record type')),
        'loan type' => implode(',', (array) $request->get('loan type')),
        'achievement details' => implode(',', (array) $request->get('achievement details')),
        'challenge details' => implode(',', (array) $request->get('challenge details')),
        'group activity type' => implode(',', (array) $request->get('group activity type')),

    ]);
    $input = $request->all();
    $input_member['first name'] = $request->get('first name');
    $input_member['other name'] = $request->get('last name');
    $input_member['id no'] = $request->get('id no');
    $input_member['phone number'] = $request->get('phone number');
    $input_member['email'] = $request->get('email');

    //input on group record types table
    $group_record_type['record type'] = implode(',', (array) $request->get('record type'));
    // try {
        DB::begin Transaction();
            $group = Group::create($input);
            $input_member['group id'] = $group->id;
            $group_record_type['group id'] = $group->id;
            $group_member =  Group Member::create($input_member);
            $group_record_type = group record types::create($group record type);
           // $group_member->send Group Member Verification Email();
        DB::commit();
      // $bug = 0;
   // } catch (\Exception $e) {
        DB::rollback();
       //$bug = $e->error Info[1];
   // }
    /* if ($bug == 0) {
        return $this->index()->with(['message success' => 'Group successfully saved.']);
    } else {
        return $this->index()->with(['message warning'=> 'Something Error Found !, Please try again.']);
    } */
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source