0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel8でSELECT LAST_INSERT_ID()をやる方法

Posted at

##insertではなくinsertGetIdメソッド?を使えばいい。

##今まで


$LastId = DB::table('table_name2')->insert(
    --処理処理--
);

##これから


$LastId = DB::table('table_name2')->insertGetId(
    --処理処理--
);

$LastIdに最後に挿入したAIの値が入る。
オートインクリメントの値しか取れないらしい?です。

普通のsqlで最後にINSERTされたIDを取得する場合は

	
SELECT LAST_INSERT_ID();

を使う様です。
でわ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?