本文整理汇总了PHP中app\models\Post::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::count方法的具体用法?PHP Post::count怎么用?PHP Post::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::count方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showList
public function showList()
{
$count = Post::count();
$posts = Post::orderBy('created_at', 'DESC')->take(6)->get();
return view('list', ['count' => $count, 'posts' => $posts]);
//будет использоваться list.blade.php
}
示例2: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($current_page)
{
$current_page = $current_page ? $current_page : 1;
$current_page = $current_page - 1;
$page = 10;
//echo $current_page*$page;exit;
$post = Post::leftJoin('websites', 'posts.website', '=', 'websites.websites_id')->leftJoin('projects', 'posts.project', '=', 'projects.projects_id')->orderby('posts_id', 'desc')->offset($current_page * $page)->limit($page);
$posts['data'] = $post->get();
$posts['count'] = Post::count();
$posts['pageSize'] = $page;
return response()->json($posts);
}
示例3: index
public function index()
{
$postsPerPage = $this->_config('posts_on_index');
// Way 1
// Define which get method to use to fetch Posts by checking ACL
// Use that function and the Model's logic to get those posts.
$unpub = $this->user->hasAccess('blog read unpublished');
$method = $unpub ? 'newest' : 'newestPublished';
$posts = models\Post::$method($postsPerPage);
// The quick 'n dirty //
$page = Options::one($_GET, 'page', 1, false);
$start = ($page - 1) * $postsPerPage;
$conditions = $unpub ? '1' : 'is_published = 1';
$posts = models\Post::all($conditions . ' ORDER BY created_on DESC LIMIT ' . $start . ', ' . $postsPerPage . '');
// Don't do it! //
// Way 2
// Define the difference in conditions here (instead of in the Model)
$conditions = $unpub ? '' : array('is_published' => true);
$numAllPosts = models\Post::count($conditions);
// Way 3
// A third way would be a combination like this:
/*
$access = $this->user->hasAccess('blog read unpublished');
$posts = model\Post::postsByAccess($access, $this->_config('posts_on_index'));
*/
// That way you can check access in the Controller and have fetch logic in the Model
$messages = Session::messages();
$canCreatePosts = $this->user->hasAccess('blog create posts');
return get_defined_vars();
// view will be rendered by row\Controller->_post_action
return $this->_display(__METHOD__, get_defined_vars(), !$this->AJAX);
// view will be rendered by Output->display
return $this->_display(get_defined_vars());
// view will be rendered by Output->display
}
示例4: getNumPosts
public function getNumPosts()
{
return \app\models\Post::count(array('author_id' => $this->user_id));
}
示例5: numPosts
public function numPosts()
{
return Post::count(array('category_id' => $this->category_id));
}
示例6: index
/**
* Dashboard index.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$postsCount = Post::count();
$commentsCount = Comment::whereSeen(0)->count();
return view('back.index', compact('postsCount', 'commentsCount'));
}