I think you have to get current auth user then simply change below line as follow $lastid=customeraddress::create($data)->id;
$lastid=customeraddress::create($data)->auth::user()->id;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 or to participate in this conversation.