本文整理汇总了PHP中app\Post::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::whereIn方法的具体用法?PHP Post::whereIn怎么用?PHP Post::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::whereIn方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: home
/**
* Shows the home page for the authenticated user.
* @return Response
*/
public function home()
{
$subscriptions = explode(',', Auth::user()->subscriptions);
$hubs = Hub::whereIn('name', $subscriptions)->get();
$posts = [];
$ids = [];
foreach ($hubs as $hub) {
$ids[] = $hub->id;
}
$posts = Post::whereIn('hub_id', $ids)->get()->sortByDesc('upvotes');
foreach ($posts as $post) {
$hub = Hub::find($post->hub_id);
if (in_array($post->user_id, explode(',', $hub->moderators))) {
$post->user_is_mod = true;
} else {
$post->user_is_mod = false;
}
$user = User::find($post->user_id);
if ($user->is_admin) {
$post->user_is_admin = true;
} else {
$post->user_is_admin = false;
}
$post->username = User::where('id', '=', $post->user_id)->firstOrFail()->username;
$post->comment_count = Comment::where('post_id', '=', $post->id)->count();
$post->hub_name = Hub::where('id', '=', $post->hub_id)->firstOrFail()->name;
}
return view('user.home', ['posts' => $posts]);
}
示例2: count_total_posts
/**
* count the total number of posts
* @return mixed
*/
public function count_total_posts()
{
$id = $this->id;
return Post::whereIn('category_id', function ($query) use($id) {
$query->select('id')->from($this->getTable())->where('parent_id', $id);
})->orWhere('category_id', $id)->whereNull('deleted_at')->count();
}
示例3: index
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
$titulo = 'Esporte, cultura e lazer';
$video = 'https://www.youtube.com/embed/G9wYHaTmpFI';
$video_nome = 'Feira Literária de São Bernardo no Cenforpe já é sucesso de público';
$cor = '#ad4b9e';
$posts = Post::whereIn('categoria_id', [3, 5, 8])->get();
$rand = array_rand(["#f77985" => "saude", "#be1039" => "educacao", "#69b843" => "infra", "#f87e3a" => "cidadania", "#2a9fe0" => "meio", "#ad4b9e" => "esporte"]);
return view('programas.categoria', compact('posts', 'titulo', 'cor', 'rand', 'video', 'video_nome'));
}
示例4: get
public static function get($category, $page)
{
$maxPerPage = Config::get('app.max_post_per_page');
if ($category == null) {
return Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->skip($maxPerPage * ($page - 1))->take($maxPerPage)->get();
} else {
$ids = Category::where('name', '=', $category)->lists('post_id');
return Post::whereIn('id', $ids)->where('lang', '=', Lang::getLocale())->where('published', '=', 1)->skip($maxPerPage * ($page - 1))->take($maxPerPage)->get();
}
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
// $posts = Post::where('category_id', $id)->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
if ($id == 0) {
$posts = Post::whereNull('deleted_at')->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
$category = null;
} else {
$category = Category::find($id);
$posts = Post::whereIn('category_id', function ($query) use($id) {
//$query->orWhere('category_id', $id);
$query->select('id')->from(with(new Category())->getTable())->where('parent_id', $id);
})->orWhere('category_id', $id)->whereNull('deleted_at')->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
}
return view('home.category.show', ['posts' => $posts, 'category' => $category]);
}
示例6: filterRecipies
/**
* Select recipies by filter
*
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function filterRecipies(Request $request)
{
$recipies = Session::get('recipies');
$idr = $recipies->pluck('id');
foreach ($request->filtergroup as $idMarker) {
if ($idMarker > 0) {
$recipies = Post::whereIn('id', $idr)->where('postStatus_id', '=', 3)->whereHas('markers', function ($q) use($idMarker, $idr) {
$q->where('markers.id', '=', $idMarker);
})->get();
$idr = $recipies->pluck('id');
}
}
Session::put('recipies', $recipies);
$title = CmsOption::getValue('Название сайта');
$metaOptions = ['filter' => $request->filtergroup];
return view('recipieGrid', ['recipies' => $recipies, 'page_title' => 'Выборка по фильтру', 'title' => $title, 'metaOptions' => $metaOptions]);
}
示例7: getMod
/**
*
*/
public function getMod(Request $request, Board $board, Post $post)
{
if (!$post->exists) {
abort(404);
}
// Take trailing arguments,
// compare them against a list of real actions,
// intersect the liss to find the true commands.
$actions = ["delete", "ban", "all", "global"];
$argList = func_get_args();
$modActions = array_intersect($actions, array_splice($argList, 2));
sort($modActions);
$ban = in_array("ban", $modActions);
$delete = in_array("delete", $modActions);
$all = in_array("all", $modActions);
$global = in_array("global", $modActions);
if (!$ban && !$delete) {
return abort(404);
}
if ($ban) {
if ($global && !$this->user->canBanGlobally()) {
return abort(403);
} else {
if (!$this->user->canBan($board)) {
return abort(403);
}
}
return $this->view(static::VIEW_MOD, ["actions" => $modActions, "form" => "ban", "board" => $board, "post" => $post, "banMaxLength" => $this->option('banMaxLength')]);
} else {
if ($delete) {
if ($global) {
if (!$this->user->canDeleteGlobally()) {
return abort(403);
}
$posts = Post::whereAuthorIP($post->author_ip)->with('reports')->get();
$this->log('log.post.delete.global', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
foreach ($posts as $post) {
Event::fire(new PostWasModerated($post, $this->user));
}
} else {
if (!$this->user->canDelete($post)) {
return abort(403);
}
if ($all) {
$posts = Post::whereAuthorIP($post->author_ip)->where('board_uri', $board->board_uri)->with('reports')->get();
$this->log('log.post.delete.local', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
foreach ($posts as $post) {
Event::fire(new PostWasModerated($post, $this->user));
}
} else {
if (!$post->isAuthoredByClient()) {
if ($post->reply_to) {
$this->log('log.post.delete.reply', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "op_id" => $post->op->board_id]);
} else {
$this->log('log.post.delete.op', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "replies" => $post->replies()->count()]);
}
}
$post->delete();
Event::fire(new PostWasModerated($post, $this->user));
}
}
return back();
}
}
return abort(403);
}
示例8: index
public function index(Request $request, Post $post)
{
$allPosts = $post->whereIn('user_id', $request->user()->following()->lists('users.id')->push($request->user()->id))->with('user');
$posts = $allPosts->orderBy('created_at', 'desc')->take($request->get('limit', 20))->get();
return response()->json(['posts' => $posts, 'total' => $allPosts->count()]);
}
示例9: feedForUser
public function feedForUser($user, $howMany = 10)
{
$groupIds = $user->follows()->lists('group_id');
return Post::whereIn('group_id', $groupIds)->latest()->simplePaginate($howMany);
}
示例10: 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'));
}
示例11: getFriendsAndUsersPosts
public static function getFriendsAndUsersPosts()
{
$friends = Friend::where('user1_id', Auth::id())->where('is_accepted', 1)->get(['user2_id']);
$friends->push(['user2_id' => Auth::id()]);
$posts = Post::whereIn('author_id', $friends)->get();
return $posts;
}
示例12: build
/**
* @param $category
* @param $page
* @return $this
*/
public function build($category, $page)
{
$morePage = 0;
$posts = Post::get($category, $page);
if ($category == null) {
if (Config::get('app.max_post_per_page') * $page < Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
$morePage = 1;
}
} else {
$ids = Category::where('name', '=', $category)->lists('post_id');
if (Config::get('app.max_post_per_page') * $page < Post::whereIn('id', $ids)->where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
$morePage = 1;
}
}
$this->statistics->incrementPage('welcome');
return view('welcome')->with(array('posts' => $posts, 'page' => $page, 'category' => $category, 'morePage' => $morePage));
}
示例13: getItemsChildeAndSelf
/**
* @return mixed
*/
public function getItemsChildeAndSelf()
{
return Post::whereIn('category_id', $this->getChildeAndSelf())->active()->sort()->paginate(15);
}