Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 449 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lumen - LengthAwarePaginator::resolveCurrentPage() is always 1

#1
With lumen, I have the problem that this is always `1`, also when I go to `/artikel?page=2`:

LengthAwarePaginator::resolveCurrentPage();

the complete code:

<?php namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;


class ArtikelController extends Controller {

public function index()
{
$dir = '../resources/views/artikel/';

$files = array_diff(scandir($dir), array('..', '.'));

$artikel = array();

foreach($files as $k => $v)
{
$id = substr($v,0,1);
$artikel[$id]['id'] = $id;
$artikel[$id]['name'] = substr($v,0,strpos($v,'.blade.php'));
}

//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();

#dd($currentPage);

//Create a new Laravel collection from the array data
$collection = new Collection($artikel);

//Define how many items we want to be visible in each page
$perPage = 2;

//Slice the collection to get the items to display in current page
$currentPageResults = $collection->slice($currentPage * $perPage, $perPage)->sortByDesc('id')->all();

//Create our paginator and pass it to the view
$paginatedResults = new LengthAwarePaginator($currentPageResults, count($collection), $perPage);

$paginatedResults->setPath('artikel');

return view('artikel', ['artikel' => $paginatedResults]);
}

I can't find the mistake. What could be the reason? (I have also updated to `"laravel/lumen-framework": "5.1.*"`)
Reply

#2
You can use this simple way to get your current page:

$currentPage = (int) app('request')->get('page', $default = '0');
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through