Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

Laravel如何取得事务提交后的自增主键id?

比如说我在Laravel的查询构造器中使用了事务,事务里面有两条insert语句,我想在正确提交事务之后取得这两条insert语句返回的自增id,如何做到?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

使用insertGetId()方法,希望对你有帮助
$id = DB::table('users')->insertGetId(

['email' => '[email protected]', 'votes' => 0]

);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...