If I understand correctly, after a call to:
$customer->save();
Can you not create a new order and do:
$order->CustId = $customer->id;
...
$order->save();
to populate the CustID column? Hopefully I interpreted your question correctly.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have created, with help from on here I have created a DB that is populating from a form on the website.
The tables I have are;
Customers Products Orders
The customers table is populating as I want and is working fine. I have a product table with 4 products and each one has its own ProdID. What I would like to do is to populate the orders table with a custID and product name(based on the user selecting from the form) under a unique auto incremeninting CustID in the customers table.
Can I do this from the same controller?
here is the booking controller
public function store(Request $request)
{
$customer = new Customer;
$customer->name = $request->name;
$customer->email = $request->email;
$customer->phone = $request->number;
$customer->comments = $request->comments;
routes
Route::get('booking',
['as' => 'booking', 'uses' => 'BookingController@create']);
Route::post('booking',
['as' => 'booking_store', 'uses' => 'BookingController@store']);
The orders tables has OrderID, CustID and Product name as its columns
Pól
No problem. You may need some logic to check if the customer already exists, and if not, only then create one. Also, for product name, are you passing the product ID on form submission? Because you can do something like:
$order->Productname = Products::find($request->product_id)->name;
"name" would be the product name given in the Products model.
Please or to participate in this conversation.