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 3 years have passed since last update.

laravel クエリビルダ saveしたカラムのIDを取得する 個人メモ

Posted at

目的

  • laravelのクエリビルダを用いてDBに値を新規で格納した時のレコードのIDを取得する方法をメモ的にまとめる

方法

  • 下記のようにする事により新規でデータを格納したレコードのIDを取得する事ができる。

    // $strにはDBに格納する値を連想配列状に格納済みであるものとする。
    $str->save();
    // 下記のようにすることで$strの内容を格納したテーブルレコードのIDを$idに格納する事できる。
    $id = $str->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?