当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::orderBy方法代码示例

本文整理汇总了PHP中app\models\Post::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::orderBy方法的具体用法?PHP Post::orderBy怎么用?PHP Post::orderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Post的用法示例。


在下文中一共展示了Post::orderBy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getIndex

 public function getIndex()
 {
     $user = Auth::user();
     $posts = Post::orderBy('updated_at', 'DESC')->get();
     // Hier später definieren, welche Posts gelesen werden dürfen
     return view('posts.index')->with('posts', $posts);
 }
开发者ID:HenOltma,项目名称:EventMap,代码行数:7,代码来源:PostController.php

示例2: 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
 }
开发者ID:Aglok,项目名称:upbrain,代码行数:7,代码来源:BlogController.php

示例3: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $search_term = $request->input('search') ? $request->input('search') : '';
     $limit = $request->input('limit') ? $request->input('limit') : 10;
     if ($search_term) {
         $posts = Post::orderBy('id', 'DESC')->where('post', 'LIKE', "%{$search_term}%")->orWhere('title', 'LIKE', "%{$search_term}%")->with(array('User' => function ($query) {
             $query->select('id', 'name');
         }))->select('id', 'title', 'post', 'user_id')->paginate($limit);
         $posts->appends(array('search' => $search_term, 'limit' => $limit));
     } else {
         $posts = Post::orderBy('id', 'DESC')->with(array('User' => function ($query) {
             $query->select('id', 'name');
         }))->select('id', 'title', 'post', 'user_id')->paginate($limit);
         $posts->appends(array('limit' => $limit));
     }
     if (!$posts) {
         return response()->json(['error' => ['message' => 'posts does not exist']], 404);
     }
     return response()->json(['data' => $this->transformCollection($posts)], 200)->setCallback($request->input('callback'));
 }
开发者ID:ganeshkanawade,项目名称:laravel-setup,代码行数:25,代码来源:PostsController.php

示例4: index

 /**
  * Display a listing of the Post.
  * GET|HEAD /posts
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $offset = $request->page ? $request->page : 1;
     $limit = $request->limit ? $request->limit : 12;
     $category = $request->category;
     $isAllow = $request->isAllow ? $request->isAllow : '';
     $offset = ($offset - 1) * $limit;
     if ($category) {
         if ($isAllow && $isAllow != '') {
             $posts = Post::where('isAllow', $isAllow)->where('category_id', $category)->orderBy('id', 'desc')->offset($offset)->limit($limit)->get();
         } else {
             $posts = Post::where('category_id', $category)->orderBy('id', 'desc')->offset($offset)->limit($limit)->get();
         }
     } else {
         if ($isAllow && $isAllow != '') {
             $posts = Post::where('isAllow', $isAllow)->orderBy('created_at', 'desc')->offset($offset)->limit($limit)->get();
         } else {
             $posts = Post::orderBy('created_at', 'desc')->offset($offset)->limit($limit)->get();
         }
     }
     return response()->json($posts);
 }
开发者ID:SawMaineK,项目名称:iwomenapp,代码行数:28,代码来源:PostAPIController.php

示例5: getHotPost

 public function getHotPost()
 {
     return Post::orderBy('votes', 'desc')->get();
 }
开发者ID:timdonat,项目名称:ketangkap,代码行数:4,代码来源:APIController.php

示例6: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = Post::orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage);
     return view('redac.posts.index', compact('posts'));
 }
开发者ID:doankhoi,项目名称:Application,代码行数:10,代码来源:PostController.php

示例7: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = Post::orderBy('created_at', 'desc')->simplePaginate(10);
     return view('web.post.index', ['posts' => $posts]);
 }
开发者ID:Su9Tail,项目名称:LaravelBlog,代码行数:10,代码来源:PostController.php

示例8: getLastPosts

 public function getLastPosts()
 {
     return Post::orderBy("created_at", "DESC")->get();
 }
开发者ID:black-bullet,项目名称:laravel-blog,代码行数:4,代码来源:Post.php


注:本文中的app\models\Post::orderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。