0
votes

In the route file ive this 2:

Route::get('/ddts', 'DdtsController@index');
Route::post('/ddts', 'DdtsController@indexByCompany');

In both controller i solved the multi pagination in one page like this:

 public function index()
    {
        //
        $ddtsValidati= Ddt::where('validato',1)->paginate(5,['*'], 'valids');
        $ddtsSospesi= Ddt::where('validato',0)->paginate(5,['*'], 'holds');
        $ddtsRifiutati= Ddt::where('validato',2)->paginate(5,['*'], 'rejects');
        $companies= \App\Models\User::where('co2','!=' , 0)->get();
        $ddt_urls= Ddt_file_url::all();

        return view('administration.ddt-management')->with('ddtsV', $ddtsValidati)->with('ddtsS',$ddtsSospesi)
            ->with('ddtsR',$ddtsRifiutati)->with('companies',$companies)->with('ddt_urls',$ddt_urls);
    }

and

 public function indexByCompany(Request $request){

        if($request->get('company_id')=='*'){
            return $this->index();
        }

        $ddtsValidati= Ddt::where([['validato',1],['company_id',$request->get('company_id')]])->paginate(5,['*'], 'valids');
        $ddtsSospesi= Ddt::where([['validato',0],['company_id',$request->get('company_id')]])->paginate(5,['*'], 'holds');
        $ddtsRifiutati= Ddt::where([['validato',2],['company_id',$request->get('company_id')]])->paginate(5,['*'], 'rejects');


        $companies= \App\Models\User::where('co2','!=' , 0)->get();
        $ddt_urls= Ddt_file_url::all();

        //$companies = Company::pluck('name', 'id')->all();->with('companies', $companies);
        return view('administration.ddt-management')->with('ddtsV', $ddtsValidati)->with('ddtsS',$ddtsSospesi)
            ->with('ddtsR',$ddtsRifiutati)->with('companies',$companies)
            ->with('ddt_urls',$ddt_urls);
    }

When I'm in the GET route (so all documents from all companies are showed) this works, but if I browse one table and then I try to browse another one the first pagination is missed and reset. This to me happen because the name of the page is forced by me! is there any simple way to solve it?

In the POST part (so when I select documents just from one company) the pagination not works, the result is correctly served ad the first, but if I try to navigate over any table the context is missed and the results are again with all documents from all companies.

1

1 Answers

2
votes

Hi if your data is not large for example 5000 or more you can use bootstrap datatable https://datatables.net/examples/styling/bootstrap

and make pagination in client side

OR

laravel create default with get parameter "page" but you can change this get parameter and set different values for each table pagination

Route::get('users', function () {
    $users = App\User::paginate(15);
    $users->withPath('custom/url');
});

see here