Return in Pagination View from Array in Laravel / Paginate :: make ()


When I create a pagination manually, it is giving error, it does not create in the view the amount of exact elements as I determine.

On my controller:

public function getIndex(){
    $fileClass = FileClass::with(['FileServico'])

    foreach($fileClass as $fileArr){
        foreach($fileArr['file_servico'] as $file){
            $f[] = $file;

    return View::make('home')
        ->with('fileClass',Paginator::make($f, count($f),2));

In the view I normally iterate to print the data and it is printed, the pager is usually created at the bottom and makes the exact count as I determine, however, the table that is created does not bring the exact elements. / p>

@foreach($fileClass as $f)
        <td>{{ $f['id_file'] }}</td>

And the pager is right, it usually appears:

    <section id="pagination">
        {{ $fileClass->links() }}

At the time of printing the number of elements per page it prints all the elements, below the pager is presented normally, but there is no pagination itself.

asked by anonymous 06.06.2014 / 01:14

1 answer


Query Builder I believe to be more practical:

 $resultado = DB::table('file_class')
    ->join('file_servico', '', '=', '') 

The $resultado already exits paged without problems only assign, for its View::make :

return View::make('home')
        ->with('fileClass', $resultado);

A good practice would be to do this in a class and just call the method:

class RepFileClass
    public function toListPaginate()
                ->join('file_servico', '', '=', '') 


06.06.2014 / 01:59