本文整理汇总了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]);
}
示例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')]);
}