Как добавить нумерацию страниц на страницу результатов поиска? - PullRequest
0 голосов
/ 24 октября 2019

Мне нужно добавить нумерацию страниц на страницу результатов. Мне нужно показать на моей странице не более 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

Ответы [ 2 ]

1 голос
/ 24 октября 2019

В вашем контроллере вы можете иметь это

$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(6);

, а в свой шаблон лезвия просто вставить это

    {{ $user->links }}

. Вышеприведенное автоматически создаст для вас пагинацию.

0 голосов
/ 24 октября 2019

используйте функцию paginate для пагинации по умолчанию в 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>
...