2016-10-14 4 views
1

첫 페이지의 페이지 매기기가 올바르게 작동합니다. 그것은 정확하게 2 개의 이름을 표시합니다. 다음 페이지에서 다른 결과를보고 싶으면 현재 코드에는 아무 것도 표시되지 않습니다. 정적 배열을 만들 때 :검색 결과 페이지 매김 laravel

$searchResults = [ 
      'item1', 
      'item2', 
      'item3', 
      'item4', 
      'item5', 
      ]; 

배열마다 다른 페이지에 올바르게 표시됩니다. SQL 쿼리에서 배열을 만들면 다음 페이지에는 아무 것도 표시되지 않습니다. var_dump를 사용했고 두 번째 페이지에서 생성 된 배열을 보지 못했습니다. 나는 다음과 같은 코드가 laravel 문서에 따라, 페이지 매김 링크를 표시하여 오류를 수정해야한다고 생각

@section('content') 

<!-- Striped rows --> 
<div class="panel panel-flat"> 
    <div class="panel-heading"> 
    <h5 class="panel-title text-center">Documentatie overzicht resultaat</h5> 
    <div class="heading-elements"> 
    </div> 
    </div> 

    <div class="text-center"> 
    <h2>Zoekresultaat van: <b><i>{{$zoekdocument}}</b></i></h5> 
    </div> 

@foreach ($results as $result) 
     <p>{{ $result }}</p> 
    @endforeach 

    <?php echo $results->render(); ?> 




@endsection 

답변

1

get()에 대해 내 코드 paginate()가 변경되어 현재 작동합니다.

0

: 이것은 내보기 코드

public function zoekdocument(Request $request) //voor het zoeken van software 
{ 

$zoekdocument = \Request::get('zoekdocument'); 

$searchResult = array(); 

$searchdoc = \DB::table('visits')->where('title', 'LIKE', '%' . $zoekdocument . '%')->paginate(); 

foreach($searchdoc as $searchdocument){ 

    $filedir = $searchdocument->pagename; //wordt gedurende loop tot die finisht in de array gezet. 

    $searchResult[] = $filedir; //dat wordt hier gedaan. 
} 

    $currentPage = LengthAwarePaginator::resolveCurrentPage(); 

    $page = $request->has('page') ? $request->get('page') : 1; 

    //Create a new Laravel collection from the array data 
    $collection = new Collection($searchResult); 

    $perPage = 2; 

    $currentPageSearchResults = $collection-> slice (($currentPage -1) * $perPage, $perPage)->all(); 
    //Create our paginator and pass it to the view 
    $paginatedSearchResults= new 

LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage, $page, ['path' => $request->url(),'query' => $request->query(), 

return view('Documentatie.result', ['results' => $paginatedSearchResults])->with('zoekdocument', $zoekdocument); 

:

내 컨트롤러 코드입니다 :

의 장소에서

{{ $users->links() }} 

https://laravel.com/docs/5.3/pagination 가 작동하는지 알려줘하고 그렇지 않으면 나는 해결책을 찾을 수 있도록 노력할 것 : 여기

<?php echo $results->render(); ?> 

는 문서 링크입니다.

+0

작동하지 않습니다. 그 이상한, 내가 정적 배열과 똑같이 할 때, 그것은 효과적이다. 내 SQL 쿼리에 의해 잘못 될 것 같아요. 내 검색어가 검색된 단어와 일치하는지 확인하고 배열을 만듭니다. 예 : keyword = "te"이고 쿼리는 데이터베이스에서 "te"라는 이름을 검색합니다. 그 후에, 그것은 루프에 의해 배열에 놓을 것이다. 다음 페이지를 클릭하면 배열이 비어 있습니다. – jurh