P
P
Pavel2019-12-25 10:17:09
Laravel
Pavel, 2019-12-25 10:17:09

How to get the id of the newly added order to the database?

All with the upcoming!
I add an order to the database and I need to get the id value of the newly added order and add it to several other tables
5e030baf34e32591288891.jpeg
. I use this method:

public function modalSend(request $request){
        $siteID = Cache::get('/' . $request->getHttpHost())->id;
        if ($request->setting != null){$settings_id = $request->settings;}else{$settings_id = null;}
        if ($request->setting != null){$category_id = $request->category;}else{$category_id = null;}
        if ($request->setting != null){$product_id = $request->product;}else{$product_id = null;}
        Orders::insert(['siteID' => $siteID, 'settings_id' => $settings_id, 'category_id' => $category_id, 'product_id' => $product_id, 'tel' => $request->tel, 'email' => $request->email, 'created_at' => date('Y-m-d H:i:s')]);
// тут мне надо достать id только что добавленного в таблицу Orders заказа и записать его в другие таблицы
// Order_message::insert...
// Order_customer::insert...
// Order_tag::insert...
// Order_goods::insert...
        return redirect()->back()->with('success', '1');
    }

Tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2019-12-25
@yatort

$id = Orders::insertGetId();
Instead of your insert

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question