YouTube Icon

Code Playground.

How to find last insert id in Laravel 5

CFG

How to find last insert id in Laravel 5

If the table has an auto-increment I d, use insertGetId to insert a record and retrieve the Key afterwards. Some times the user inserts a record into the table and finds the inserted I d and inserts another table with this I d.

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




CFG