自定义 Bootstrap 分页 Laravel 错误

Custom Bootstrap Pagination in Laravel error

我遵循网站上的文档 https://medium.com/appstract/custom-bootstrap-pagination-in-laravel-540922f71af0

但我有两个问题: 这是我的代码

Route::get(‘rows’, ‘ComeController@rows’);

第一个:

public function rows(Request $request)
{
$search_cons=$request->all();
$tablename=$search_cons[‘tablename’];
$search_alls = DB::table($tablename)
->where(‘product’,’=’,’5');

(1.)
    ->get();
    ?//it shows Method links does not exist

(2).
    ->>paginate(9);
    //it will ocupy the $perPage=9  when I use dd($search_alls)



   $page =   $request->get(‘page’, 1);
    $perPage = 6;
    $items = collect($myItems);
    return view(‘my.view’, [ ‘items’ => $items->forPage($page, $perPage), ‘pagination’ => BootstrapComponents::pagination($items, $page, $perPage, ‘’, [‘arrows’ => true]) ]);
}

第二个:

when click the page link to the page2 just like http://…/rows?page=2
it shows Undefined index: tablename

我使用 ->paginage(9) 吗?但是 $perpage 缺少它的功能

LengthAwarePaginator {#279 ▼
  #total: 13
  #lastPage: 2
  #items: Collection {#262 ▶}
  #perPage: 9
  #currentPage: 1
  #path: "http://localhost:8000/comefoshowmain"
  #query: []
  #fragment: null
  #pageName: "page"
}

我该如何修复 ?page=2 错误?


感谢回复

我只想使用分页,但是当我点击第 2 页时我的代码显示错误

这是我认为不使用 bootstrap 组件的起源

web.php

Route::get('rows','ProController@rows');

Pro控制器:

public function rows(Request $request)
{
    $search_cons=$request->all();

$tablename=$search_cons['tablename'];

$search_alls = DB::table($tablename)
    ->where('product','=','5')
    ->paginate(9);

    return View('pro.results')
            ->with('search_alls', $search_alls)
            ->with('table',$tablename);

};

results.blade 查看

<div class="container">
@foreach ($search_alls->chunk(3) as $chunks)
    <div class="row clearfix">
      @foreach($chunks as $searchall)
        <div class="col-md-4 column">
                <h3>
                    label
                </h3>
                <p>
                    something             
        </p>
        </div>
      @endforeach
    </div>
@endforeach
</div>
{!! $search_alls->links() !!}

首页效果不错

http://localhost:8000/rows?table=A16&...

当我点击第二页时

localhost:8000/行?page=2

显示

显示未定义索引:表名

是的,原因是您需要在分页中附加当前查询字符串 link 我的代码是

$input = Request::input();
$myModelsPaginator = App\Models\MyModel::paginate();
$myModelsPaginator->appends($input);

给你喜欢这个

 $input = Request::input();
 $search_alls = DB::table($tablename)
 ->where(‘product’,’=’,’5');
->pagination(9);
 $searcg_alls->appends($input);

将您的 table 名称和所有其他输入附加到页面 link 这样您就不会收到 table 未找到错误

你的问题不清楚,但假设如上所述你想要的不是然后评论下来可能我会帮助你