public function index(Status $status) { if (Auth::check()) { $userIds = Auth::user()->followedUsers()->lists('followed_id'); $userIds[] = Auth::user()->id; // WhereIn to find where a column's value equals the value in an array // Eager loading comments $statuses = $status->with('comments')->whereIn('user_id', $userIds)->latest()->get(); } else { $statuses = $status->all(); } return view('statuses.index')->with('statuses', $statuses); }
public function index() { $statuses = Status::with('likes', 'comments.user', 'user.profile')->latest('updated_at')->get(); return view('discussions.index')->with(compact('statuses')); }