1

I am currently trying to save the current page from Pagination throughout my project pages.

Why?

The reason is that I would like to go to a detail page of let's say data xy in an overview list, maybe even say I would like to edit it, but then decide to go back to the overview list of all data.

So this would mean:

overview page --> select data xy (detailpage) --> edit data xy (edit page)

overview page <--------- go back from edit data xy (edit page)

My Controller code:

public function index(Request $request, $current_page = 1)
{
  $data = self::paginate(11);
  return $data;
  if($current_page) $data->current_page = $current_page;

  return view('dashboard.data.index')->with(array('data' => $data));
}

public function details(Request $request, $id, $current_page = 1)
{
    $datadetail = Data::where('id', $id)->firstOrFail();

    return view('dashboard.data.detail')->with(array('detail' => $datadetail, 'current_page' => $current_page));
}

This is not working. When I click on the following button on detail view:

<a class="btn btn-primary btn-back" href="{{ URL::action("DataController@index", array('current_page' => $current_page)) }}"><span class="glyphicon glyphicon-chevron-left"></span></a>

this leads back to the overview page, BUT always to page 1, even if it was handed over originally from index to detail view as 3 or 4...

My question:

How can I tell the Paginator to load the page number I am handing over?

Mentenyia
  • 211
  • 1
  • 4
  • 10
  • Possible duplicate of [Laravel 5.1 specifing current page for pagination](http://stackoverflow.com/questions/31747801/laravel-5-1-specifing-current-page-for-pagination) – Jeremy Harris Nov 17 '16 at 13:13
  • @JeremyHarris thank you for that, but my problem is, that the detail view is resetting the $currentPage value to 1 when clicking on the button. – Mentenyia Nov 17 '16 at 13:33

1 Answers1

0

Ok, the problem was the routes. The page parameter needs to be in the url, otherwise it will reset to default value.

Mentenyia
  • 211
  • 1
  • 4
  • 10