How to get last inserted id through save() method in laravel

后端 未结 6 1780
醉酒成梦
醉酒成梦 2021-01-22 03:37

I know to get the last id I can use insertGetId() but I want to know how can I get the last inserted id through save() method.

order =          


        
6条回答
  •  遇见更好的自我
    2021-01-22 04:12

    You can get the last inserted id by the following codes.

    Using Laravel Eloquent

    $order = new Store_order();
    $order->invoice_id = $signed['invoice_id'];
    $order->save();
    
    $lastInsertedId = $order->so_id;     //now getting Last inserted id
    echo $lastInsertedId; 
    

    Provided that $order->so_id means last inserted id of the given object where so_id is the primary key of the table.

提交回复
热议问题