alphadev
2 months ago

how to save data from one form into different db tables

Posted 2 months ago by alphadev

hi m working on a form which has two different parts, and only one part works at a time and I have to comment one part to use the other: (m using resource routes for both)

controller:

    public function store(Request $request)
        {
            //dd($request->all());
            $request->validate([
                'patient_name' => 'required',
                'patient_insurance' => 'required',
                'patient_insurance_id' => 'required',
                'patient_reason' => 'required',
                'patient_new' => 'required',
                'patient_contact_no' => 'required',
                'patient_message' => 'required',
            ]);

            /*
            DB::table('userdatas')->insert([
                'patient_fname' => $request->patient_fname,
                'patient_lname' => $request->patient_lname,
                'patient_email' => $request->patient_email,
                'patient_dob' => $request->patient_dob,
                'patient_guardian' => $request->patient_guardian,
                'patient_gender' => $request->patient_gender, 
                'user_id' => $request->user_id,
            ]);
            */

            DB::table('forms')->insert([
                'patient_name' => $request->patient_name,
                'patient_insurance' => $request->patient_insurance,
                'patient_insurance_id' => $request->patient_insurance_id,
                'patient_reason' => $request->patient_reason,
                'patient_new' => $request->patient_new,
                'patient_contact_no' => $request->patient_contact_no,
                'patient_message' => $request->patient_message,

            ]);
            return back();
        }

this is form: https://paste.ofcode.org/tB9y3h2h85Raf457uJiszU

I need suggestion to solve it?

Please sign in or create an account to participate in this conversation.