EMfinanga
4 months ago

insert selected id into another table

Posted 4 months ago by EMfinanga

I have already created my customer into database, in my HTML form i managed to select those customer

I want to insert customer_id into another, because this customer_id is carry multiple data/input into customersales table.

my code below is inserted the id but it create another id into customeraddresses table. how can i insert without create another customer_id??

My code i tried

                $data=$request->all();
        $lastid=customeraddress::create($data)->id;
        if(count($request->product_name) > 0)
        {
            foreach($request->product_name as $Customeraddress=>$v){
                $data2=array(
                    'customer_id'=>$lastid,
                    'payment_status'=>$request->payment_status[$Customeraddress],
                    'product_name'=>$request->product_name[$Customeraddress],
                    'quantity'=>$request->quantity[$Customeraddress],
                    'price'=>$request->price[$Customeraddress],
                    'amount'=>$request->amount[$Customeraddress],
                );

                customer::insert($data2);

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