Reputation: 811
I follow the doc on the site https://medium.com/appstract/custom-bootstrap-pagination-in-laravel-540922f71af0
but I got two question: here is my code
Route::get(‘rows’, ‘ComeController@rows’);
first:
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
or
(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]) ]);
}
Second:
when click the page link to the page2 just like http://…/rows?page=2
it shows Undefined index: tablename
Does I use the ->paginage(9)? but the $perpage is missing its function
LengthAwarePaginator {#279 ▼
#total: 13
#lastPage: 2
#items: Collection {#262 ▶}
#perPage: 9
#currentPage: 1
#path: "http://localhost:8000/comefoshowmain"
#query: []
#fragment: null
#pageName: "page"
}
And how can I fix the ?page=2 error?
Thanks for the reply
I just want to use pagination but my code show error when I click the page 2
here is my origin thought not using the bootstrap component
web.php
Route::get('rows','ProController@rows');
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);
};
<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() !!}
The first page work well
http://localhost:8000/rows?table=A16&...
when I click the second page
localhost:8000/rows?page=2
it shows
it shows Undefined index: tablename
Upvotes: 0
Views: 837
Reputation: 2936
yes the reason because you need to append current querystring in pagination link this my code is
$input = Request::input();
$myModelsPaginator = App\Models\MyModel::paginate();
$myModelsPaginator->appends($input);
FOR YOU LIKE THIS
$input = Request::input();
$search_alls = DB::table($tablename)
->where(‘product’,’=’,’5');
->pagination(9);
$searcg_alls->appends($input);
append you table name and all other input with page link so you not get table not found error
your question is not clear but assume as above you want is no then comment down may be i help you
Upvotes: 1