1
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.

オブジェクトのoriginal属性からデータを取り出す。Eloquent Model 【Laravel】

Posted at

##オブジェクトのoriginal属性からデータを取り出す。

###やりたいこと
モデル名->取り出したい変数名とするとattributesから取り出されてしまうが、originalから取り出したい。

  

     #attributes: array:6 [▼
        "id" => 1097
        "user_id" => 1
        "title" => "タイトル"
        "body" => "ボディー"
        "created_at" => "2021-05-13 00:08:27"
        "updated_at" => "2021-05-13 00:08:27"
      ]
      #original: array:10 [▼
        "id" => 1097
        "user_id" => 1
        "title" => "タイトル"
        "body" => "ボディー"
        "created_at" => "2021-05-13 00:08:27"
        "updated_at" => "2021-05-13 00:08:27"
        "pivot_user_id" => 1
        "pivot_language_id" => 1097
        "pivot_created_at" => "2021-06-10 19:32:40"
        "pivot_updated_at" => "2021-06-10 19:32:40"

とりだしたいのはpivot_created_atの時間。

 $post->getOriginal()['pivot_created_at'];

解決。

1
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
1
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?