当前位置: 首页>>代码示例>>PHP>>正文


PHP City::take方法代码示例

本文整理汇总了PHP中app\City::take方法的典型用法代码示例。如果您正苦于以下问题:PHP City::take方法的具体用法?PHP City::take怎么用?PHP City::take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\City的用法示例。


在下文中一共展示了City::take方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: homeSearch

 public function homeSearch()
 {
     DB::connection()->enableQueryLog();
     $user_config = array('keywords' => \Input::get('keywords'), 'location' => \Input::get('location'));
     $ltype = '';
     if (!is_numeric($user_config['location'])) {
         if (strpos($user_config['location'], ',') === false) {
             $data['location'] = $user_config['location'];
             $ltype = 'city';
         } else {
             $loc = explode(', ', $user_config['location']);
             $data['search_city'] = $loc[0];
             $data['search_state'] = $loc[1];
             $data['location'] = $data['search_city'] . ', ' . $data['search_state'];
             $ltype = 'default';
         }
     } else {
         //Assign zip code to the data
         $data['location'] = $user_config['location'];
         $ltype = 'zip';
     }
     //Get the filter options matching the location
     $data['filter_options']['city'] = \App\City::take(5)->get();
     if (count(Input::get()) == 3) {
         if ($ltype == 'default') {
             $search_type = 'default';
         } elseif ($ltype == 'city') {
             $search_type = 'default_city';
         } else {
             $search_type = 'default_zip';
         }
     } else {
         if ($ltype == 'default') {
             $search_type = 'filter';
         } elseif ($ltype == 'city') {
             $search_type = 'filter_city';
         } else {
             $search_type = 'filter_zip';
         }
     }
     //echo $search_type;
     //dd(Input::get());
     switch ($search_type) {
         case 'default':
             $data['restaurants'] = \App\Restaurants::join('city', 'city.id', '=', 'restaurants.city_id')->join('state', 'state.id', '=', 'restaurants.state_id')->join('restaurants_info', 'restaurants_info.restaurants_id', '=', 'restaurants.id')->where(function ($query) use($user_config) {
                 $query->where('restaurants.name', 'LIKE', '%' . $user_config['keywords'] . '%')->orWhere('restaurants.categories', 'LIKE', '%' . $user_config['keywords'] . '%');
             })->where('city.city', '=', $loc[0])->where('state.short', '=', $loc[1])->orderBy('restaurants.rank', 'desc')->orderBy('restaurants.categories', 'asc')->paginate(10);
             foreach ($data['restaurants'] as $rest) {
                 $reviews = $this->getReviewsThree($rest->permalink);
                 //$data['restaurants'][$rest->permalink] = $rest;
                 $rest->reviews_group = $reviews;
                 //dd($rest);
             }
             $data['meta_title'] = 'Find the Best ' . $user_config['keywords'] . ' Restaurants in ' . $loc[0] . ', ' . $loc[1] . ' | Restaurant Listings|';
             $data['meta_description'] = $user_config['keywords'] . ' in ' . $loc[0] . ', ' . $loc[1] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             $data['meta_keywords'] = $loc[0] . ', ' . $loc[1] . ', ' . $user_config['keywords'] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             session(["search_city" => $loc[0], "search_state" => $loc[1], "search_zip" => ""]);
             break;
         case 'default_city':
             $data['restaurants'] = \App\Restaurants::join('city', 'city.id', '=', 'restaurants.city_id')->join('restaurants_info', 'restaurants_info.restaurants_id', '=', 'restaurants.id')->where(function ($query) use($user_config) {
                 $query->where('restaurants.name', 'LIKE', '%' . $user_config['keywords'] . '%')->orWhere('restaurants.categories', 'LIKE', '%' . $user_config['keywords'] . '%');
             })->where('city.city', '=', $data['location'])->orderBy('restaurants.rank', 'desc')->orderBy('restaurants.categories', 'asc')->paginate(10);
             foreach ($data['restaurants'] as $rest) {
                 $reviews = $this->getReviewsThree($rest->permalink);
                 //$data['restaurants'][$rest->permalink] = $rest;
                 $rest->reviews_group = $reviews;
                 //dd($rest);
             }
             $data['meta_title'] = 'Find the Best ' . $user_config['keywords'] . ' Restaurants in ' . $data['location'] . ' | Restaurant Listings|';
             $data['meta_description'] = $user_config['keywords'] . ' in ' . $data['location'] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             $data['meta_keywords'] = $data['location'] . ', ' . $user_config['keywords'] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             session(["search_city" => $data['location'], "search_state" => "", "search_zip" => ""]);
             break;
         case 'default_zip':
             //Get restaurants matching the keywords and the location
             $data['restaurants'] = \App\Restaurants::join('city', 'city.id', '=', 'restaurants.city_id')->join('state', 'state.id', '=', 'restaurants.state_id')->join('restaurants_info', 'restaurants_info.restaurants_id', '=', 'restaurants.id')->where(function ($query) use($user_config) {
                 $query->where('restaurants.name', 'LIKE', '%' . $user_config['keywords'] . '%')->orWhere('restaurants.categories', 'LIKE', '%' . $user_config['keywords'] . '%');
             })->where('restaurants.zip', 'LIKE', $user_config['location'])->orderBy('restaurants.rank', 'desc')->orderBy('restaurants.categories', 'asc')->paginate(10);
             foreach ($data['restaurants'] as $rest) {
                 $reviews = $this->getReviewsThree($rest->permalink);
                 //$data['restaurants'][$rest->permalink] = $rest;
                 $rest->reviews_group = $reviews;
                 //dd($rest);
             }
             $data['meta_title'] = 'Find the Best ' . $user_config['keywords'] . ' Restaurants in ' . $user_config['location'] . ' | Restaurant Listings|';
             $data['meta_description'] = $user_config['keywords'] . ' in ' . $user_config['location'] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             $data['meta_keywords'] = $user_config['location'] . ', ' . $user_config['keywords'] . ' Online food Order, Get Menu, Reviews, Contact, Location Maps, Directions';
             session(["search_city" => "", "search_state" => "", "search_zip" => $user_config['location']]);
             break;
         case 'filter':
             $data['restaurants'] = \App\Restaurants::join('city', 'city.id', '=', 'restaurants.city_id')->join('state', 'state.id', '=', 'restaurants.state_id')->join('restaurants_info', 'restaurants_info.restaurants_id', '=', 'restaurants.id')->where(function ($query) use($user_config) {
                 $query->where('restaurants.name', 'LIKE', '%' . $user_config['keywords'] . '%')->orWhere('restaurants.categories', 'LIKE', '%' . $user_config['keywords'] . '%');
             })->where('city.city', '=', $loc[0])->where('state.short', '=', $loc[1])->where(function ($query) {
                 $category = Input::has('category') ? Input::get('category') : NULL;
                 if (isset($category)) {
                     foreach ($category as $c) {
                         $query->orWhere('restaurants.categories', 'LIKE', '%' . $c . '%');
                     }
                 }
                 $ordering = Input::has('ordering') ? Input::get('ordering') : NULL;
//.........这里部分代码省略.........
开发者ID:RestaurantListings,项目名称:restaurant_listings,代码行数:101,代码来源:SearchController.php


注:本文中的app\City::take方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。