teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

リレーションの命名規則に従い修正。

2017/10/04 01:22

投稿

masaya_ohashi
masaya_ohashi

スコア9210

answer CHANGED
@@ -3,11 +3,11 @@
3
3
  $base_list = Base::with(['ref'])->all();
4
4
  foreach($base_list as $index => $base) {
5
5
  if($base->ref_type == 'Hoge') {
6
- $base->image;
6
+ $base->images;
7
7
  }
8
8
  }
9
9
  // [
10
- // ['id' => 1, 'ref_id' => 1, 'ref_type' => 'Hoge', 'ref' => [id => 1, 'name' => 'hoge', 'number' => 0, 'image' => ['id' => 1, 'hoge_id' => 1, 'path' => 'image.jpg']]],
10
+ // ['id' => 1, 'ref_id' => 1, 'ref_type' => 'Hoge', 'ref' => [id => 1, 'name' => 'hoge', 'number' => 0, 'images' => [['id' => 1, 'hoge_id' => 1, 'path' => 'image.jpg']]]],
11
11
  // ['id' => 2, 'ref_id' => 1, 'ref_type' => 'Fuga', 'ref' => [id => 1, 'name' => 'fuga', 'text' => 'a']],
12
12
  // ]
13
13
  ```