Return new id with DB::insert() in Laravel 4

后端 未结 6 778
情歌与酒
情歌与酒 2020-12-29 20:12

In Laravel 4, when you perform a DB::insert(), how can you get the ID of the row that has just been inserted? Similar what we have with the function ->

6条回答
  •  旧巷少年郎
    2020-12-29 20:22

    There is a insertGetId() method, as follows:

    $dataset = array('column_id' => 1, 'name' => 'Dayle');
    $column_id = DB::table('users')->insertGetId($dataset,'column_id');
    

提交回复
热议问题