本文整理匯總了PHP中app\Post::sortPosts方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::sortPosts方法的具體用法?PHP Post::sortPosts怎麽用?PHP Post::sortPosts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Post
的用法示例。
在下文中一共展示了Post::sortPosts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getPosts
/**
* Gets the social media posts for the specified $hashtag.
*
* @example array($post1, $post2, $post3)
* @param string $term hashtag term to search for
* @return array|object
*/
protected function getPosts($term)
{
// search social media provider feeds for the specified hashtag term
$posts = $this->searchHashtag($term);
// sort posts
Post::sortPosts($posts, \Session::get('sort_by'));
// merge posts with current user's saved posts
$this->mergePosts($posts);
return $posts;
}
示例2: getUserPosts
/**
* Gets the current user's saved posts. Returns an empty Collection if user
* is not logged in.
*
* @example array($post1, $post2, $post3)
* @return array|object
*/
protected function getUserPosts()
{
// if a user is logged in, then return the user's saved posts
// otherwise, return an empty array
$user_posts = \Auth::check() ? \Auth::user()->posts->all() : [];
// sort user's saved posts
Post::sortPosts($user_posts, \Session::get('sort_by'));
return $user_posts;
}