本文整理汇总了PHP中app\Profile::take方法的典型用法代码示例。如果您正苦于以下问题:PHP Profile::take方法的具体用法?PHP Profile::take怎么用?PHP Profile::take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Profile
的用法示例。
在下文中一共展示了Profile::take方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterPosts
public function filterPosts(Request $request)
{
$query = $request->city_id ? 'city_id = ' . (int) $request->city_id . ' AND ' : NULL;
$query .= $request->image == 'on' ? 'image IS NOT NULL AND ' : NULL;
$query .= $request->from ? 'price >= ' . (int) $request->from . ' AND ' : 'price >= 0 AND ';
$query .= $request->to ? 'price <= ' . (int) $request->to : 'price <= 9999999999';
if ($request->text) {
$text = trim(strip_tags($request->text));
$query .= " AND (title LIKE '%{$text}%' or description LIKE '%{$text}%')";
}
$section = Section::all();
$profiles = Profile::take(5)->get();
if ($request->category_id) {
$section = Section::find($request->category_id);
$posts = Post::where('status', 1)->where('category_id', $request->category_id)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
$posts->appends(['category_id' => (int) $request->category_id, 'city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to, 'tag_id' => $request->tags_id]);
} else {
$posts = Post::where('status', 1)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
$posts->appends(['city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to, 'tag_id' => $request->tags_id]);
}
$selected_tags = [];
if (isset($request->tags_id)) {
$selected_tags = $request->tags_id;
foreach ($posts as $post_key => $post) {
$hasTag = false;
foreach ($selected_tags as $tag_id) {
if ($post->hasTag($tag_id)) {
$hasTag = true;
}
}
if (!$hasTag) {
unset($posts[$post_key]);
}
}
}
$category = Category::findOrFail($request->category_id);
$category_tags = $category->tags()->get();
$favorites = ProfileController::getFavorites($request);
$favorites = $favorites ? $favorites : [];
return view('board.posts', compact('category', 'category_tags', 'selected_tags', 'section', 'sections', 'profiles', 'posts', 'favorites'));
}
示例2: showMyFavorites
public function showMyFavorites(Request $request)
{
$favorites = $this->getFavorites($request);
$favorites = $favorites ? $favorites : [];
$profiles = Profile::take(5)->get();
$posts = Post::whereIn('id', array_values($favorites))->orderBy('id', 'DESC')->get();
return view('profile.my_favorites', compact('posts', 'favorites', 'profiles'));
}
示例3: filterPosts
public function filterPosts(Request $request)
{
$query = $request->city_id ? 'city_id = ' . (int) $request->city_id . ' AND ' : NULL;
$query .= $request->image == 'on' ? 'image IS NOT NULL AND ' : NULL;
$query .= $request->from ? 'price >= ' . (int) $request->from . ' AND ' : 'price >= 0 AND ';
$query .= $request->to ? 'price <= ' . (int) $request->to : 'price <= 9999999';
if ($request->text) {
$text = trim(strip_tags($request->text));
$query .= " AND (title LIKE '%{$text}%' or description LIKE '%{$text}%')";
}
$sections = Section::all();
$profiles = Profile::take(5)->get();
if ($request->section_id) {
$section = Section::find($request->section_id);
$posts = Post::where('status', 1)->where('section_id', $request->section_id)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
$posts->appends(['section_id' => (int) $request->section_id, 'city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to]);
} else {
$posts = Post::where('status', 1)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
$posts->appends(['city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to]);
}
return view('board.found_posts', compact('section', 'sections', 'profiles', 'posts'));
}