public function bodyStateCity($id) { $this->layout->body_class = ''; $body = Body::find(explode("-", $id)[0]); $state = null; foreach ($this->getStates() as $entity) { if (explode("-", $id)[1] == $entity['code']) { $state = $entity; break; } } $columns = array(array(), array(), array()); $cities = DB::select(DB::raw("SELECT DISTINCT city FROM vehicle WHERE body = :body AND state = :state ORDER BY city"), array('body' => $body->id, 'state' => $state['code'])); foreach ($cities as $key => $value) { $location = Location::where('state', '=', $state['code'])->where('city', '=', $value->city); if ($location->count()) { $zip = $location->first()->zip_code; $link = '/search?body=' . $body->id . '&zip_code=' . $zip . '&distance=50&page=1&sort=price-1'; $title = $body->body . ' for sale near ' . $value->city . ', ' . $state['code']; $city = array('link' => $link, 'title' => $title); array_push($columns[$key % 3], $city); } } $data = array('search_text' => '', 'body' => $body, 'state' => $state, 'columns' => $columns); $this->layout->contents = View::make('browse/body-state-city', $data); }