How to find last insert id in Laravel 5

If the table has an auto-incrementing id, use the insertGetId method to insert a record and then retrieve the ID. Many time user insert one record in table and find inserted id and this id insert another table.

$insert_id = DB::table('hold_history')->insertGetId(
    ['loat_no' => "GJHAEF", 
     'hold_for' => "alex",
     'on_hold_by' => '250',
     'status' => '1'
    ]
);

Leave a Reply

Your email address will not be published. Required fields are marked *