本文整理汇总了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);
}
示例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
}
示例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'));
}
示例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);
}
示例5: getHotPost
public function getHotPost()
{
return Post::orderBy('votes', 'desc')->get();
}
示例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'));
}
示例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]);
}
示例8: getLastPosts
public function getLastPosts()
{
return Post::orderBy("created_at", "DESC")->get();
}