當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。