public function showLinen($group, $colour) { $catSlug = 'linen'; $catName = 'Linen'; $groupId = Group::where('slug', '=', $group)->first(); $colourId = Colour::where('slug', '=', $colour)->first(); $group_id = "%"; $groupSlug = '0'; if ($group !== '0') { $group_id = $groupId->id; $groupSlug = $groupId->slug; $groupName = $groupId->name; } $colour_id = "%"; $colourSlug = '0'; $colourHex = '0'; if ($colour !== '0') { $colour_id = $colourId->id; $colourSlug = $colourId->slug; $colourHex = $colourId->hex; } //Living nightmare to work out how to get this to order on the collection field. //Seems you have to use the function to joing the products anf then run the eager load $results = colour::with(['product' => function ($query) { $query->select('products.*')->join('groups', 'group_id', '=', 'groups.id')->orderBy('groups.collection', 'ASC'); }, 'product.group'])->where('id', '=', $colour_id)->paginate(100); //return $results; $groups = Group::where('cat_id', 'LIKE', 60)->get(); $colours = Colour::orderby('order')->get(); $cat = 'linen'; $cat_id = 60; session::put('colour', $colourHex); Session::flash('keywords', 'linen, Tablecloths, napkins'); Session::flash('title', 'Linen'); //return $results[0]; return View::make('results', compact('results', 'groups', 'groupSlug', 'colours', 'colourId', 'cat', 'cat_id', 'catSlug', 'groupName', 'catName')); //return View::make('results'); }