public function sequence($item) { $collections = collect($this->paginator->items()); $index = $collections->search($item) + 1; $start = (request('page', 1) - 1) * $this->paginator->perPage(); return $start + $index; }
public function getIndex(Request $request, Bus $bus) { $userId = $request->user()->id; $page = $request->input('page') ?: 1; $perPage = config('inoplate.notification.per_page', 10); $items = collect($this->notifRepository->get($userId, $page, $perPage)); $total = $this->notifRepository->count($userId); $paginator = new LengthAwarePaginator($items, $total, $perPage, $page); $paginator->setPath('/admin/inoplate-notification/notifications'); $items = $paginator->items(); return $this->getResponse('inoplate-notification::notifications.index', ['notifications' => $paginator->toArray()]); }
/** * @param LengthAwarePaginator|LengthAwarePaginatorContract $paginator * @param string $dataKey * * @return array */ protected function paginatorToArray(LengthAwarePaginator $paginator, $dataKey = 'items') { return ['total' => $paginator->total(), 'perPage' => $paginator->perPage(), 'currentPage' => $paginator->currentPage(), 'lastPage' => $paginator->lastPage(), 'nextPageUrl' => $paginator->nextPageUrl(), 'prevPageUrl' => $paginator->previousPageUrl(), 'from' => $paginator->firstItem(), 'to' => $paginator->lastItem(), $dataKey => $paginator->items()]; }