Support the ongoing development of Laravel.io →
Input Database Views
Last updated 2 years ago.
0

oops too hard for anyone to solve

0

bikedel said:

oops too hard for anyone to solve

I could be so much more sarcastic in a response ....

Anyways, I'm not sure what to tell you. I made a rest route and simi-duplicated the code you provided and it works or me.

\\ Laravel 5.1

Route::get('/test11', function (Request $request) {

    // get the current page
    $currentPage = Input::get('page', 1);

    // set the current page
    \Illuminate\Pagination\Paginator::currentPageResolver(function () use ($currentPage) {
        return $currentPage;
    });

    // paginate with a length of 3 records
    $menu = Menu::simplePaginate(3);

    // return as json to view
    // return $menu;

    // using stringblade for render test, so i didnt need to make a template file
    $template = '{!! $menu->render() !!}
    @foreach ($menu as $m)
    {{$m["id"]}} - {{$m["caption"]}}<BR>
    @endforeach';

    return view( ['template' => $template, 'secondsTemplateCacheExpires' => 0], ['menu' => $menu, 'page' => $currentPage ] );;

});
0

Hi TerrePorter

Thanks sooo much for the reply and not taking the sarcastic bait...

I will have a look at your solution and let you know how it went.

Thanks again!

Regards Bikedel

0

Hi TerrePorter

I set the page using the exact same function you used, as in my explanation.

I am using a simplePaginate(1) - I am displaying a page per record - I cant use simplePaginate(3).

It get's me to the correct page but I cannot move back or next.

Regards Bikedel

0

Ha Ha Bait!

The 'simplePaginate(3)' part specifies how many to put on each page, I just randomly selected that number on my end.

How are you accessing the next/prev?

I would make sure that your getting the next/prev links in the $properties, maybe returning it and looking at the json data.

Another test would be to manually change pages /www/?page=2 and see if that works, it could be just a problem with the link being displayed or the perhaps the routing maybe.

0

Happy Friday

I am using {!! $properties->render() !!}
manually changing pages does not work when I use currentPageResolver it's as if the result from the db query only returned 1 row

Without using currentPageResolver : I am able to get the page number I want to change to in the view and setup a link to that page but it needs to go there automatically

0

ok, I am doing things backwards

I have just realised I am not looking to go to a specific page but rather a specific item !

because I use paginate(1) - I am kinda using each item as a page

0

dangling a small chocolate

0

acemary4918 what has your post got to do with my issue????

0

bikedel said:

Happy Friday

I am using {!! $properties->render() !!}
manually changing pages does not work when I use currentPageResolver it's as if the result from the db query only returned 1 row

Without using currentPageResolver : I am able to get the page number I want to change to in the view and setup a link to that page but it needs to go there automatically

I'm going to lean toward it is something wrong with the route.

You could try making a test route, like what I did, then once you have the code working there, then move it to the controller function.

bikedel said:

ok, I am doing things backwards

I have just realised I am not looking to go to a specific page but rather a specific item !

because I use paginate(1) - I am kinda using each item as a page

The problem is that if your item is on page 1 today and page 4 tomorrow. You could loop the currentPageResolver and simplePaginate, increasing the page number until you find the right page to display. That would mean the {!! $properties->render() !!} might not be used, since it will be pages not specific items.

But if your doing it this way, why use the paginate, just load all of the items in to a array and use JavaScript to do the paging.

0

Hi TerrePorter

I will try the test route you described.

Thanks for you time, it is appreciated.

0

Thanks TerrePorter, the problem was in my route. Fixed now thanks for your time.

ROUTE Route::get('/erf/{id}?page={item}', 'ErfController@test');

CONTROLLER

$currentPage = $item; Paginator::currentPageResolver(function() use ($currentPage) { return $currentPage; });

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

bikedel bikedel Joined 9 Mar 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.