sergionader's avatar

Update records/pagination after reloading the view.

Scenario:

  1. I have a view, dealers.blade, that shows in a the contents of a single table.
  2. the view has a pagination control,{{$dealers->links()}}, and the controller sends pagianate(10) to the view. The
  3. The records of the dealers table are added by importing an excel file.
  4. the file upload field and the importer button are in the same blade.

Question:

  1. say we have 20 dealers. When I access the view, I can see pages 1 and 2 on the pagination control. This is fine.
  2. now, using the very same page, I select a file, upload it and add to the dealers table. Dealer table now has 40 records/
  3. the pagination control should show 4 pages, but it is still showing 2 pages (because the previous count was 20 records). In other words, the view is still showing the same old 20 records.
  4. Now I import 10 more records and the view now shows 4 pages (from the previous import) instead of five.
  5. in any case, if I hit the "go to the last record" button, the pagination control is updated by itself. After importing the data, I call the view using: return view('app.dealers',[<<variables>>]);

Basically I need to show the new records when I call the view again. If the new records are show, the pagination control will be updated by itself, I guess.

TIA!

0 likes
5 replies
jlrdw's avatar

If everything is properly ran through the controller the pagination will be correct. But after importing 20 records of course the pagination order will change and you may have to start fresh with page one again.

Snapey's avatar

After you upload the file, don't return the view directly in the same call. Return a redirect, forcing the browser to reload the page.

sergionader's avatar

Thanks, Snapey. I tried it but got an error. I will try again and see what is going on.

Snapey's avatar

show your controller if necessary

sergionader's avatar

Snapey, it worked. The way I did it some hours ago was creating an infinite load loop.

Please or to participate in this conversation.