如何在我的搜索结果页上添加分页?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在我的搜索结果页上添加分页?相关的知识,希望对你有一定的参考价值。

我需要在结果页中添加分页。我需要在我的页面上显示最多6个帖子,以及添加分页之后。如何将其添加到功能中?我正在使用Laravel 5.2版。我现在确定是否可以使用render()

这里是我的控制器:

 $user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
                      ->where('career_solutions.topic_category_id', '=', $c)
        ->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
        ->join('roles' , 'roles.id', '=', 'role_users.role_id')
        ->join('users', 'users.id', '=', 'career_solutions.user_id')
        ->join('categories', 'categories.id', '=', 'career_solutions.topic_category_id')
        ->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
        ->orWhere ( 'career_solutions.id', '=', 'events.subject')
        ->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
        ->orWhere ( 'career_solutions.user_id', '=', 'users.username')
       ->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id','categories.category')
         ->get ();

这是我的观点:

<?php $count_event = 1; ?>
        @foreach($details as $user)
    @if($count_event == 1)


<div class="news-v2-desc" style="background-color: #f7f8fa">
<div class="row">
  <div class="col-md-2">

    <?php $img = "thumbnail/".$user->profile_picture; ?>

    @if(@getimagesize($img))
      <img style="position: relative;top: 9px;" class="img-circle noticeboard-profile-picture-neo col-md-2" src="{{ url('ass/50/50?'.$img) }}" alt="">
    @endif
  </div>
  <div class="col-md-10 noticeboard-subjecttitle">
    <h4 class="noticeboard-title" style="text-align: justify;position: relative;right: -15px;">

      <a href="{{ url( $test ) }}/{{ $user->id }}_{{ Slugify::slugify( $user->subject  ) }}" class="noticeboard-subject">{{ $user->subject }} </a>


    </h4>

    <ul style="position: relative;right: -15px" class="list-unstyled list-inline blog-info noticeboard-ul-link">
      <li>
        @if($user->role_id == 1)
        <i class="icon-user"></i>
        <a href="{{ url('')}}/{{$user->username}}">{{$user->username}}</a>
        @else
        <i class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
        <a href="{{ url('')}}/{{$user->username}}">{{$user->username}}</a>
        @endif

      </li>
      <li>
        <i style="font-size: 11px" class="icon-{{$typee}}"></i>
        <a href="{{ url('') }}/{{$link}}">{{ $type }}</a>
      </li>
                        </ul>
  </div>
</div>

<p><a style="border-radius: 0rem !important;border: 0.1rem solid #18ba9b" class="btn-z btn-xs  g-mr-10 g-mb-15" href="{{ url( $test ) }}/{{ $user->id }}_{{ Slugify::slugify( $user->subject  ) }}">Read more <i class="fa fa-angle-double-right margin-left-5"></i></a></p>
</div>
</div>
@endif

答案

使用分页功能在laravel中进行默认分页

$paginate = 6;
 $user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
                      ->where('career_solutions.topic_category_id', '=', $c)
        ->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
        ->join('roles' , 'roles.id', '=', 'role_users.role_id')
        ->join('users', 'users.id', '=', 'career_solutions.user_id')
        ->join('categories', 'categories.id', '=', 'career_solutions.topic_category_id')
        ->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
        ->orWhere ( 'career_solutions.id', '=', 'events.subject')
        ->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
        ->orWhere ( 'career_solutions.user_id', '=', 'users.username')
       ->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id','categories.category')
         ->paginate($paginate);

也用于刀片模板

<ul class="pagination">
        {!! $user->render() !!}
    </ul>

以上是关于如何在我的搜索结果页上添加分页?的主要内容,如果未能解决你的问题,请参考以下文章

text Wp在任何页面上添加分页

如何在 UICollectionView 中快速添加分页?

向我的mysql查询添加分页[重复]

如何使我的图像停留在一页上而不重复?

如何在laravel中搜索产品页面添加分页

从后面的子母版页代码访问子母版页上的用户控件