0
votes

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

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 view

<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

1
What is the question? You have an error Undefined index: tablename OR ?page=2 error? ? Can you specify your requirement changes other than usual pagination cases? You don't need to worry about any other things if you follow the official Laravel Pagination format.Eazy Sam
@robspin Unclear your question Please describe more, then we will help you.AddWeb Solution Pvt Ltd
@EazySam I repost my question for the ?page=2robspin
@AddWebSolutionPvtLtd I repost my question just use the laravel pagination functionrobspin
use origin pagination I use this to fix . {{ $users->appends($_GET)->links() }} But can I use post methoud for pagination route::post('rows','ProController@rows') And {{ $users->appends($_POST)->links() }} I got the erroe message Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No messagerobspin

1 Answers

1
votes

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