當前位置: 首頁>>代碼示例>>PHP>>正文


PHP City::first方法代碼示例

本文整理匯總了PHP中app\City::first方法的典型用法代碼示例。如果您正苦於以下問題:PHP City::first方法的具體用法?PHP City::first怎麽用?PHP City::first使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\City的用法示例。


在下文中一共展示了City::first方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: detectUserLocation

 public static function detectUserLocation()
 {
     $city = [NULL];
     if (auth()->check()) {
         $user = auth()->user();
         // $city = $user->profile->city()->get();
     } else {
         $user_location = GeoIP::getLocation();
         $city = City::where('slug', $user_location['city'])->get();
     }
     if (empty($city[0])) {
         $city[0] = City::first();
     }
     view()->share('user_city', $city[0]);
 }
開發者ID:vizovteam,項目名稱:vizov,代碼行數:15,代碼來源:User.php

示例2: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $this->validate($request, ['city_id' => 'integer|exists:city,id', 'tag_id' => 'integer|exists:tag,id', 'type' => 'string|in:' . implode(',', Place::types())]);
     if ($request->has('city_id')) {
         $city = City::find($request->input('city_id'));
     } else {
         $city = City::where('geoname_id', 658225)->first();
         if (!count($city)) {
             $city = City::first();
         }
     }
     $query = Place::where('city_id', $city->id);
     if ($request->has('search')) {
         $words = explode(" ", $request->input('search'));
         $query->whereHas('translations', function ($sub_query) use($words) {
             foreach ($words as $word) {
                 // If it is Chinese, use LIKE. Else, use full text index.
                 // http://www.regular-expressions.info/unicode.html#script
                 if (preg_match('/\\p{Han}+/u', $word)) {
                     $sub_query->where(function ($q) use($word) {
                         $q->where('name', 'like', '%' . $word . '%')->orWhere('content', 'like', '%' . $word . '%');
                     });
                 } else {
                     $sub_query->whereRaw('MATCH(name,content) AGAINST(? IN BOOLEAN MODE)', [$word . '*']);
                 }
             }
         });
     }
     if ($request->has('type')) {
         $query = $query->where('type', $request->input('type'));
     }
     if ($request->has('tag_id')) {
         $query = $query->whereHas('tags', function ($sub_query) use($request) {
             $sub_query->where('id', $request->input('tag_id'));
         });
     }
     $query->with('image');
     $places = $query->orderBy('like_count', 'desc')->paginate(24);
     return view('pages.place.index', ['places' => $places, 'city' => $city, 'type' => $request->input('type')]);
 }
開發者ID:santakani,項目名稱:santakani.com,代碼行數:45,代碼來源:PlaceController.php


注:本文中的app\City::first方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。