Call to a member function pluck() on null

来源:10-5 使用多对多模型实现个人中心逻辑(上)

天晖

2017-06-25

老师,个人中心页面中:

// 获取关注用户及他们的关注、粉丝、文章数

$stars = $user->starts;

$susers = User::whereIn('id', $stars->pluck('star_id'))->withCount(['stars', 'fans', 'posts'])->get();

// 获取粉丝用户及他们的关注、粉丝、文章数

$fans = $user->fans;

$fusers = User::whereIn('id', $fans->pluck('fan_id'))->withCount(['stars', 'fans', 'posts'])->get();

报: Call to a member function pluck() on null 错:

http://szimg.mukewang.com/594f7a8c00010c5e10480309.jpg

Fan模型代码:

http://szimg.mukewang.com/594f7aa5000138ed05570445.jpg

Post模型代码:

http://szimg.mukewang.com/594f7abc0001276406711081.jpg

User模型代码:

http://szimg.mukewang.com/594f7aea0001a90106081006.jpg

User控制器:

http://szimg.mukewang.com/594f7b1a0001df3e09610589.jpg

写回答

1回答

轩脉刃

2017-06-29

$user->starts  应该是 $user->stars

0
0

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程