How to paginate Laravel Analytics Collection data

67 Views Asked by At

I am using Laravel Analytics and calling Analytics data, I am trying to paginate the data but cannot:

Controller:

public function analytics()
{   
    $analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(1))->paginate(10);
    $no = 0;
    return view('admin.analytics',compact(['analyticsData', 'TotalVisitors', 'no']));
}

Views:

<table class="table table-hover">
    <thead>
      <tr>
        <th>S.No.</th>
        <th scope="col">Date</th>
        <th scope="col">Visitors</th>
        <th scope="col">PageTitle</th>
        <th scope="col">PageViews</th>
      </tr>
    </thead>
      <tbody>
        @foreach ($analyticsData->sortBy('pageViews')->reverse() as $data)
        <tr>
          <td>{{ ++$no }}</td>
          <td>{{ $data['date'] }}</td>
          <td>{{ $data['visitors'] }}</td>
          <td>{{ $data['pageTitle'] }}</td>
          <td>{{ $data['pageViews'] }}</td>
        </tr>
        @endforeach
      </tbody>
</table>
 @if( $analyticsData->count() != 0 )    
 {{ $analyticsData->links('pagination::bootstrap-4') }}
 @endif

But I get an error: Method Illuminate\Support\Collection::paginate does not exist.

dd($analyticsData);

gives me:

enter image description here

0

There are 0 best solutions below