2018-11-12 17:05
浏览 29

流明 - 分页链接()方法不起作用

I am trying to create a paginated resultset in Lumen. I am not using a database collection, instead it is an array collection.

I have managed to get the results to display, however I am having a problem getting the pagination links() method to work. Here is what I have:



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;

class AppController extends Controller
    public function index(Request $request)
        $items = [

        $collection = collect($items);

        $currentPage = LengthAwarePaginator::resolveCurrentPage();
        $perPage = 2;
        $offset = ($currentPage * $perPage) - $perPage;

        $currentPageResults = $collection->slice($offset, $perPage)->all();

        $paginatedItems = new LengthAwarePaginator($currentPageResults, count($collection), $perPage);


        return view('index', [
            'results' => $paginatedItems,


    @foreach ($results as $result)
        <li>{{ $result }}</li>

    {{ $results->links() }}

The error I am getting is:

call_user_func() expects parameter 1 to be a valid callback, no array or string given

If I remove $results->links() I don't get the error.

When I dd($paginationItems) I do get back a valid LengthAwarePaginator object:

enter image description here

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmengsuo9302 2018-11-12 17:32

    I found the answer:

    Within bootstrap/app.php there is a line of code commented out by default:

    // $app->withEloquent();

    This needs to be uncommented for the pagination links() method to work.

    解决 无用
    打赏 举报

相关推荐 更多相似问题