0
votes

I want to do pagination for this select but I have no idea where I can do this

  $files = $files->groupBy('file.id_file')->orderBy('data_meet', 'desc')->paginate(30);

And i get this error:

Call to undefined method Illuminate\Database\Eloquent\Collection::links()

View:

    <div class="container">
        @foreach ($files as $file)
            {{ $files->file }}
        @endforeach
    </div>
{{ $files->links() }}
1
No need just try to return the "$files" you would see if any wrong happenedNour
To return like this? with paginate at the last line?Suan1957
You have some errors in your code I will write it again for youNour
use {!! $files->render() !!}Mandeep Gill
just hardcoded at the bottom this..but nothing else happensSuan1957

1 Answers

0
votes

As I saw from your pervious code your problem is you are trying to apply simple pagination on a collection which is not allowed try this

$files = $files->groupBy('file.id_file')->orderBy('data_meet', 'desc')->get(); 
$currentPage = LengthAwarePaginator::resolveCurrentPage();
        $collection = new Collection($files);
        $perPage = 15;
        $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
        $result= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);

and then pass $result instead of $files and the rest is still the same