/** * Display a listing of the businesses. Front page view * Guest users will see a list of all businesses. * Logged in users will see a list of businesses they're following followed by a list of all others * @return Response */ public function index() { $businesses = Business::all(); if (Auth::check()) { $user = Auth::user(); $followingBusinessIds = $user->following()->lists('id'); //array of business ids of business the user is following //Get all businesses the user is not following $businesses = Business::whereNotIn('id', $followingBusinessIds)->get(); } return view('businesses.index', compact('businesses')); //return view('businesses.index')->where('businesses', $businesses); }