首页 文章

Laravel错误中的自定义Bootstrap分页

提问于
浏览
0

我按照网站上的文档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');

ProController:

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& ...

当我点击第二页时

本地主机:8000 /行页= 2

表明

它显示未定义的索引:tablename

1 回答

  • 1

    是的原因是因为你需要在我的代码所在的分页链接中附加当前查询字符串

    $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);
    

    使用页面链接附加表名和所有其他输入,这样就不会出现表未找到错误

    你的问题不明确,但假设如上所述你不想那么评论可能是我帮助你

相关问题