2013-02-14 2 views
0

결과이 내가 내 컨트롤러Laravel - Paginating 웅변 검색된는

$projects=Project::where_sup_id($user_id)->get(); 
    $total=count($projects); 
    $per_page=3; 
    $projects = Paginator::make($projects, $total, $per_page); 
    return View::make('project.index')->with('projects',$projects); 

에있는 그리고이 내보기에

@foreach ($projects->results as $project) 

     {{$project->title}} 

@endforeach 


{{$projects->links();}} 

하지만 난 그것을 모두 모든 행을 표시하는 브라우저에서 볼 때 페이지 ... 링크가 완벽하게 표시됩니다! 제 생각에는 그게 문제 죠? 도와주세요! 미리 감사드립니다!

+0

오류가 수정되어 다른 것으로 끝났습니다.'-> results'에 대한 필요성을 잊지 마십시오.'객체가 아닌 객체의 속성을 얻으려고 시도 중입니다. '오류가 발생합니다. – BSchlinker

답변

3

모든 행을 계산 중이지만 limit을 전혀 사용하지 않는 경우 Laravel 유창 쿼리 작성기는 skip()take() 방법을 사용합니다.

Btw를 수동으로 페이지 매김하지 않아도됩니다. Laravel은 paginate() 메서드를 사용하여 페이지 매김을 자동으로 수행합니다.

$projects = Project::where_sup_id($user_id)->paginate(3); // 3 means records per page 
return View::make('project.index')->with('projects', $projects); 

당신은 제대로 view 작업을하고있다 :

는 그런 식으로 작업을 수행합니다.