当前位置: 首页>>代码示例>>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;未经允许,请勿转载。