Laravel - Query Builder - Auto Incrementing Ids

If the table has an auto-incrementing id, use the insertGetId method to insert a record and then retrieve the ID:

    
    $id = DB::table('users')->insertGetId(
        ['email' => '[email protected]', 'votes' => 0]
    );
	
When using PostgreSQL the insertGetId method expects the auto-incrementing column to be named id. If you would like to retrieve the ID from a different "sequence", you may pass the column name as the second parameter to the insertGetId method.