-3
I’ve been messing with Laravel for a little while and I’ve got a problem... I need to return the id of a table in the database to feed the foreign key from another table and I’m not getting it.
How did I get the id that was entered last?
$customer = new Customer();
$customer->name_customer = $request->input('name');
$customer->cpf_customer = $request->input('cpf');
$customer->email_customer = $request->input('email');
$result = $customer->save();
$sales = new Sale();
$sales->date_sale = $formatDate;
$sales->quant_sale = $request->input('quantity');
$sales->deduction_sale = $finalValue;
$sales->name_product_sold = $request->input('product');
$sales->status_sale = $request->input('status');
$sales->sales_customer_id = $customer->customer_id;
$result = $sales->save();
I created the object Customer and I’m trying to catch the customer_id
down, but it’s coming like null
Laravel Framework 7.25.0 Mysql
What version of Laravel and PHP are you using? What database? This information is important for us to help you. If possible include this information in your question.
– Mauro Rocha
If my answer answered what you wanted, please mark as the answer to your question to be answered.
– Mauro Rocha