本文整理汇总了PHP中Post::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::orderBy方法的具体用法?PHP Post::orderBy怎么用?PHP Post::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::orderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIndex
/**
* Returns all the blog posts.
*
* @return View
*/
public function getIndex()
{
// Get all the blog posts
$posts = $this->post->orderBy('created_at', 'DESC')->paginate(10);
// Show the page
return View::make('site/blog/index', compact('posts'));
}
示例2: getIndex
/**
* Returns all the blog posts.
*
* @return View
*/
public function getIndex()
{
// $home = $this->post->where('slug', '=', 'home')->first();
// if(count($home) == 1){
// return Theme::make('site/blog/home', compact('home'));
// } else {
$posts = $this->post->orderBy('created_at', 'DESC')->paginate(10);
return Theme::make('site/blog/index', compact('posts'));
// }
}
示例3: getIndex
public function getIndex()
{
$posts = Post::orderBy('id', 'desc')->paginate(10);
$posts->getEnvironment()->setViewName('pagination::simple');
$this->layout->title = 'Home Page | Laravel 4 Blog';
$this->layout->main = View::make('home')->nest('content', 'index', compact('posts'));
}
示例4: getIndex
/**
* Show a list of all the blog posts.
*
* @return View
*/
public function getIndex()
{
// Grab all the blog posts
$posts = Post::orderBy('created_at', 'DESC')->paginate(10);
// Show the page
return View::make('admin/blogs/index', compact('posts'));
}
示例5: index
/**
* Display a listing of latest questions.
*
* @return Response
*/
public function index()
{
$sort = array('name' => '', 'direction' => '');
switch (Input::get('sort')) {
case 'newest':
$sort['name'] = 'created_at';
$sort['direction'] = 'desc';
break;
case 'oldest':
$sort['name'] = 'created_at';
$sort['direction'] = 'asc';
case 'most viewed':
$sort['name'] = 'view_count';
$sort['direction'] = 'desc';
break;
default:
$sort['name'] = 'created_at';
$sort['direction'] = 'desc';
break;
}
$questions = Post::orderBy($sort['name'], $sort['direction'])->where('post_type_id', '=', '1')->paginate(10);
$tags = Tag::all();
$data = array('questions' => $questions, 'tags' => $tags);
// return var_dump($posts);
return View::make('public.questions.index', $data);
}
示例6: adminIndexAll
public function adminIndexAll()
{
$posts = Post::orderBy('updated_at', 'desc')->paginate();
return View::make('admin.dicts.list', ['columns' => ['ID', 'Пользователь', 'Текст', 'Рубрика', 'Лайки', 'Комментарии', 'Время', '', ''], 'data' => $posts->transform(function ($post) {
return ['id' => $post->id, 'user' => link_to("admin/users{$post->user_id}", $post->user->name), 'text' => link_to("admin/posts/{$post->id}/edit", $post->text), 'category' => link_to("/admin/categories/{$post->category_id}/edit", $post->category->title), 'likes' => link_to("admin/posts/{$post->id}/likes", $post->likes->count()), 'comments' => link_to("admin/posts/{$post->id}/comments", $post->comments->count()), 'time' => Carbon::createFromTimestamp($post->created_at), 'edit' => link_to("/admin/posts/{$post->id}/edit", 'редактировать'), 'delete' => link_to("/admin/posts/{$post->id}/delete", 'удалить')];
}), 'actions' => [['link' => 'admin/posts/delete', 'text' => 'Удалить выбранное']], 'links' => $posts->links(), 'title' => 'Посты']);
}
示例7: run
public function run()
{
$faker = Faker\Factory::create();
DB::table('favorites')->truncate();
foreach (range(1, 30) as $index) {
$post = Post::orderBy(DB::raw('RAND()'))->first();
User::orderBy(DB::raw('RAND()'))->first()->favorites()->attach($post->id);
}
}
示例8: search
public function search()
{
//TODO Rate limit
$query = Input::get('query');
$max = Input::has('size') && Input::get('size') < 61 ? Input::get('size') : 25;
$last = Input::has('last') ? Input::get('last') : Post::orderBy('id', 'desc')->first()->id;
$posts = Post::where('text', 'ilike', '%' . $query . '%')->where('id', '<', $last)->orderBy('id', 'desc')->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->take($max)->get();
return $this->respond($this->collectionTransformer->transformPosts($posts));
}
示例9: it_orders_the_values
/** @test **/
public function it_orders_the_values()
{
$this->createPostsTable();
$this->insertOn('posts', ['title' => 'House', 'content' => 'Repeating']);
$this->insertOn('posts', ['title' => 'Sherlock', 'content' => 'Elementary Watson.']);
$this->insertOn('posts', ['title' => 'Psych!', 'content' => 'Repeating']);
$posts = Post::orderBy('title', 'DESC')->get();
$this->assertEquals('Sherlock', $posts->first()->title);
$this->assertEquals('House', $posts->last()->title);
}
示例10: APIGetImages
public function APIGetImages()
{
$posts = Post::orderBy('id', 'DESC')->where('group_id', $this->id)->get();
$returnStr = array();
foreach ($posts as $post) {
if ($post->statustype == 'image') {
$returnStr[] = $post->displayAPIMontage();
}
}
return $returnStr;
}
示例11: index
/**
* Display a listing of videos
*
* @return Response
*/
public function index()
{
$search_value = Input::get('s');
if (!empty($search_value)) {
$posts = Post::where('title', 'LIKE', '%' . $search_value . '%')->orderBy('created_at', 'desc')->paginate(10);
} else {
$posts = Post::orderBy('created_at', 'DESC')->paginate(10);
}
$user = Auth::user();
$data = array('posts' => $posts, 'user' => $user, 'admin_user' => Auth::user());
return View::make('admin.posts.index', $data);
}
示例12: rankings
public function rankings()
{
//Top 10 usuarios
$top10user = UserProfile::orderBy('points', 'desc')->take(10)->get();
//Top 10 mejores publicaciones - Todo el tiempo
$top10post = Post::orderBy('point', 'desc')->take(10)->get();
//Top 10 mejores publicaciones - Mes
$top10month = Post::where('created_at', '>=', new DateTime('-1 months'))->orderBy('point', 'desc')->take(10)->get();
//Top 10 mejores publicaciones - Mes
$top10week = Post::where('created_at', '>=', new DateTime('-1 weeks'))->orderBy('point', 'desc')->take(10)->get();
return View::make('ranking', ['top10user' => $top10user, 'top10post' => $top10post, 'top10month' => $top10month, 'top10week' => $top10week]);
}
示例13: blog
public function blog()
{
$this->load->model('post');
$this->load->library('pagination');
$posts = Post::all();
$config['base_url'] = base_url() . 'blog/page/';
$config['total_rows'] = $posts->count();
$config['per_page'] = 5;
$skip = ($this->uri->segment(3) - 1) * $config['per_page'];
$this->pagination->initialize($config);
$data = ['menu' => 'blog', 'posts' => Post::orderBy('created_at', 'desc')->skip($skip)->take($config['per_page'])->get(), 'links' => $this->pagination->create_links()];
$this->load->view('front/blog', $data);
}
示例14: trending
public function trending()
{
$data['page'] = 'trending';
$data['pagetype'] = 'trending';
$data['images'] = Post::select('posts.*', DB::raw('count(votes.id) as total'))->leftJoin('votes', 'posts.id', '=', 'votes.post_id')->groupBy('posts.id')->orderBy('total', 'desc');
if (Auth::user()) {
$data['images'] = $data['images']->with(array('votes' => function ($query) {
$query->where('user_id', Auth::id());
}))->take(12)->get();
} else {
$data['images'] = $data['images']->take(12)->get();
}
$data['others'] = Post::orderBy(DB::raw('RAND()'))->take(10)->get();
return View::make('scrollpost')->with($data);
}
示例15: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
/*$posts = Post::all();
$this->layout->title = 'Liste des articles';
$this->layout->main = View::make('dash')->nest('content','posts.index',compact('posts'));*/
$sortby = Input::get('sortby');
$order = Input::get('order');
if ($sortby && $order) {
$posts = Post::orderBy($sortby, $order)->paginate(10);
} else {
$posts = Post::orderBy('created_at', 'DESC')->paginate(10);
}
$this->layout->title = 'Liste des articles';
$this->layout->main = View::make('dash')->nest('content', 'posts.index', compact('posts', 'sortby', 'order'));
}