【发布时间】:2018-09-02 19:36:17
【问题描述】:
我关注网站上的文档 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
我使用 ->page(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 页时我的代码显示错误
这是我不使用引导组件的起源
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&...
当我点击第二页时
localhost:8000/rows?page=2
它显示
它显示未定义的索引:表名
【问题讨论】:
-
问题是什么?你有一个错误 Undefined index: tablename OR ?page=2 error? ?除了通常的分页案例之外,您能否指定您的需求更改?如果您遵循官方的 Laravel Pagination 格式,则无需担心其他任何事情。
-
@robspin 不清楚你的问题请描述更多,然后我们会帮助你。
-
@EazySam 我为 ?page=2 重新发布我的问题
-
@AddWebSolutionPvtLtd 我重新发布我的问题只是使用 laravel 分页功能
-
使用原始分页我用这个来修复。 {{ $users->appends($_GET)->links() }} 但是我可以使用 post 方法进行分页 route::post('rows','ProController@rows') 和 {{ $users->appends( $_POST)->links() }} 我收到错误消息 Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message
标签: laravel pagination bootstrap-4 custom-component