laravel6で配列の中の配列の値を取り出したいのですが、なかなか上手く出来なくて積んでいます。
どの記事を読んでも、解決策が出ないので教えていただけるとありがたいです。
吐き出しているエラー
Trying to get property 'name' of non-object
php
1var_dump(json_decode($test['0']['test']));
/work/storage/framework/views/f985ef2ffa16de1244e9381f39e04e0ab8e4727f.php:30:
object(stdClass)[412]
public 'id' => int 1
public 'test_group_id' => int 1
public 'title' => string 'test'
public 'deleted_at' => null
public 'created_at' => string '2020-01-13 07:40:45'
public 'updated_at' => string '2020-01-13 07:40:45'
public 'test_group' =>
object(stdClass)[423]
public 'id' => int 1
public 'name' => string 'test'
public 'deleted_at' => null
public 'created_at' => string '2020-01-13 07:40:45'
public 'updated_at' => string '2020-01-13 07:40:45'
上記がvardumpの結果です。
下にあるtest_groupの配列を取り出したいのですがうまくいきません。
blade
1 @foreach($tests as $k => $v) 2<p>{{$v->test->name}}</p> ←取り出せる 3<p>{{$v->test_group->name}}</p> ←取り出せない 4@endforeach
リレーションの方法が間違っているのでしょうか・・?
回答1件
あなたの回答
tips
プレビュー