/** * Paginates a collection. For simple pagination, one can override this function * * a little help from http://laravelsnippets.com/snippets/custom-data-pagination * * @param Collection $data * @param int $perPage * @param Request $request * @param null $page * * @return LengthAwarePaginator */ public function paginateCollection(Collection $data, $perPage, Request $request, $page = null) { $pg = $request->get('page'); $page = $page ? (int) $page * 1 : (isset($pg) ? (int) $request->get('page') * 1 : 1); $offset = $page * $perPage - $perPage; return new LengthAwarePaginator($data->splice($offset, $perPage), $data->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]); }
public function testSplice() { $data = new Collection(['foo', 'baz']); $data->splice(1); $this->assertEquals(['foo'], $data->all()); $data = new Collection(['foo', 'baz']); $data->splice(1, 0, 'bar'); $this->assertEquals(['foo', 'bar', 'baz'], $data->all()); $data = new Collection(['foo', 'baz']); $data->splice(1, 1); $this->assertEquals(['foo'], $data->all()); $data = new Collection(['foo', 'baz']); $cut = $data->splice(1, 1, 'bar'); $this->assertEquals(['foo', 'bar'], $data->all()); $this->assertEquals(['baz'], $cut->all()); }
public function limpiarUltimoPedido() { $this->lista->splice(0, 1); \Cache::put($this->keyCola, $this->lista, 1440); }
/** * Splice a portion of the underlying content. * * @param int $offset * @param int|null $length * @param mixed $replacement * @return $this */ protected function spliceContent($offset, $length = null, $replacement = []) { $replacement = $this->prepareContentsForInsertion($replacement); $this->html_contents->splice($offset, $length, $replacement->toArray()); return $this; }
protected function summarizeTopBrowsers(Collection $topBrowsers, int $maxResults) : Collection { return $topBrowsers->take($maxResults - 1)->push(['browser' => 'Others', 'sessions' => $topBrowsers->splice($maxResults - 1)->sum('sessions')]); }