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