本文整理汇总了PHP中app\Post::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::orderBy方法的具体用法?PHP Post::orderBy怎么用?PHP Post::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::orderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$posts = Post::orderBy('date_start', 'DESC')->get();
$postPublish = Post::countAllPostsPublished()->get();
$postUnpublish = Post::countAllPostsUnpublished()->get();
return view('post.index', compact('posts', 'postPublish', 'postUnpublish'));
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$hashtag = $this->argument('hashtag');
$GetterClass = '\\App\\Getters\\' . $this->argument('provider') . 'Getter';
$TransformerClass = 'App\\Transformers\\' . $this->argument('provider') . 'Transformer';
$getter = new $GetterClass();
$this->info('Getting posts from ' . $this->argument('provider'));
$posts = $getter->getList($this->argument('howmany'), $this->argument('hashtag'));
// transform posts
foreach ($posts as $key => $post) {
$transformer = new $TransformerClass($post);
$currentPost = $transformer->get();
// store if it doesn't already exist
if (!Post::has($currentPost['post_id'])) {
// check if post is popular enough
if ($this->argument('qualityThreshold')) {
if ($transformer->isPopular($this->argument('qualityThreshold'))) {
Post::create($currentPost);
}
} else {
Post::create($currentPost);
}
}
}
// Cache last 50 posts
$this->comment('Caching last fifty posts');
$lastFiftyPosts = \App\Post::orderBy('date_published', 'DESC')->take(50)->get();
Cache::put('lastFiftyPosts', $lastFiftyPosts, 5);
}
示例3: getIndex
public function getIndex()
{
$posts = Post::orderBy('created_at', 'desc')->take(5)->get();
$products = Product::orderBy('created_at', 'desc')->take(5)->get();
$references = Reference::orderBy('created_at', 'desc')->take(5)->get();
return view('admin/index', ['posts' => $posts, 'products' => $products, 'references' => $references]);
}
示例4: index
public function index()
{
$posts = Post::orderBy('page_view', 'DESC')->get();
$pageType = 'Random';
$data = compact('posts', 'pageType');
return view('posts.index', $data);
}
示例5: index
public function index()
{
$postType = '文章總覽';
$posts = \App\Post::orderBy('created_at', 'desc')->paginate(5);
$data = compact('postType', 'posts');
return view('posts.index', $data);
}
示例6: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = Post::orderBy('created_at', 'desc')->paginate(6, ['*'], 'p');
$comments = Comment::all();
$data = ['comments' => $comments, 'posts' => $posts];
return view('posts.index', $data);
}
示例7: feed
public function feed()
{
$feed = Feed::make();
// cache the feed for 60 minutes (second parameter is optional)
$feed->setCache(60, 'laravelFeedKey');
// check if there is cached feed and build new only if is not
if (!$feed->isCached()) {
// creating rss feed with our most recent 20 posts
$posts = Post::orderBy('created_at')->take(20)->get();
// set your feed's title, description, link, pubdate and language
//FIXME: These are duplicated
$feed->title = config('seotools.meta.defaults.title');
$feed->description = config('seotools.meta.defaults.description');
$feed->logo = 'http://yoursite.tld/logo.jpg';
$feed->link = route('feed');
$feed->setDateFormat('datetime');
// 'datetime', 'timestamp' or 'carbon'
$feed->pubdate = $posts[0]->created_at;
$feed->lang = 'en';
$feed->setShortening(true);
// true or false
$feed->setTextLimit(200);
// maximum length of description text
foreach ($posts as $post) {
// set item's title, author, url, pubdate, description and content
$image = null;
if ($post->coverImage) {
$image = ['url' => url($post->coverImage), 'type' => 'image/jpeg'];
}
$feed->add($post->title, 'Jesse Collis', $post->url(), $post->created_at, $post->subtitle, $post->body, $image);
}
}
return $feed->render('atom');
}
示例8: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
// $posts = Post::all();
// $data = ['posts' => $posts,];
// 自動分頁
$posts = Post::orderBy('created_at', 'desc')->paginate(5);
$data = compact('posts');
return view('posts.index', $data);
}
示例9: index
public function index()
{
/* return view('admin.post.index')
->withPosts(Post::all());*/
$posts = Post::orderBy('published_at', 'desc')->paginate(config('blog.posts_per_page'));
//分页配置
return view('admin.post.index', compact('posts'));
//分页
}
示例10: index
public function index()
{
if (Input::has('group_id')) {
$posts = Post::where('group_id', Input::get('group_id'))->paginate(10)->toArray();
} else {
$posts = Post::orderBy('id', 'desc')->paginate(10)->toArray();
}
return view('admin.posts.index', compact('posts'));
}
示例11: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
if (Auth::check()) {
$skip = Input::get('p') * 10;
$posts = Post::orderBy('points', 'desc')->take(10)->skip($skip)->get();
return view('newsfeed', ['posts' => $posts]);
} else {
return view('splash', ['submitted' => FALSE]);
}
}
示例12: updateSideBarCache
public static function updateSideBarCache()
{
$categories = Category::all();
$posts = Post::orderBy('updated_at', 'desc')->limit(2)->get();
if (Cache::has('categories') || Cache::has('posts')) {
Cache::flush();
}
Cache::forever('posts', compact('posts'));
Cache::forever('categories', compact('categories'));
}
示例13: index
public function index()
{
if (Auth::user()->admin) {
$posts = Post::orderBy('created_at', 'desc')->get();
return view('admin.index', ['posts' => $posts]);
} else {
$posts = Post::where('autor_id', Auth::user()->id)->orderBy('created_at', 'desc')->get();
return view('autor.index', ['posts' => $posts]);
}
}
示例14: index
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$search = $request->get("search");
if (!empty($search)) {
$posts = Post::where('name', 'Like', '%' . $search . '%')->orderBy('created_at', 'DESC')->paginate(3);
} else {
$posts = Post::orderBy('created_at', 'DESC')->paginate(3);
}
return view("posts.index", compact("posts"));
}
示例15: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index($category_id = null)
{
// if a category was passed, use that
// if no category, get all posts
// if ($category_id) {
// $posts = Post::where('category_id', $category_id);
// }
// else {
$posts = Post::orderBy('created_at', 'DESC')->paginate(15);
// }
return view('posts.index', ['posts' => $posts]);
}