laravel5.5 获取数值的语法?
期望获取值category_id: 3,4
category_id = {{print_r($post->categories['category_id'])}} // at view
ErrorException (E_ERROR)
Undefined index: category_id
[upl-image-preview url=http://static.forum.laravelacademy.org/assets/files/2017-11-24/1511470507-64330-category-post.jpeg]
3 Comments
先打印下
$post->categories
就明白了$post->categorie 列表一大堆其中有category_id=3,category_id=4
如何书写正确的语法?谢谢!
@martin#1222
public function hasManyCategories()
{
return $this->hasMany(Category::class, 'post_id', 'id');
}