dimanche 24 septembre 2017

Laravel 5 Paginator returns first page only

I have a fairly simple chatlog viewer which uses a Laravel paginator to easily separate the returned logs into pages. Unfortunately, the paginator only ever returns the first page of results, even though it renders the number of pages correctly.

Here's the controller code:

public function search(Requests\ChatSearchRequest $request)
{
    //split search up into what we've got

    $request->flash();

    $nick = $request->input('nick');
    $message = $request->input('message');
    $channel = $request->input('channel');
    $time_start = $request->input('datestart');
    $time_end = $request->input('dateend');
    $sortby = $request->input('sortby');
    $limit = (int) $request->input('limit');
    $page = (int) $request->input('page');


    $query = ChatMessage::query();

    if (!empty($nick))
        $query->usersLike($nick);
    if (!empty($channel))
        $query->fromChannel($channel);
    if (!empty($message))
        $query->matchMessage($message);
    if (!empty($time_start))
        $query->betweenTimes($time_start, $time_end);

    $query->orderBy('id', $sortby);

    $messageResults = $query->take($limit)->get();

    $messages = new LengthAwarePaginator($messageResults->all(), $messageResults->count(), 100, $page, ['path' => Paginator::resolveCurrentPath(), 'query' => $request->query()]);

    return view('chatlog', compact('messages'));
}

And here's what a request generated by the form the page uses looks like:

http://localhost/chatlog/search?message=&nick=Saten&channel=&datestart=2017-09-17T14%3A50%3A44&dateend=2017-09-24T14%3A50%3A44&limit=250&sortby=desc&page=3

I've tried a bunch of things from other questions asked here to no avail. I've tried using Paginator::resolveCurrentPage() in lieu of pulling page from requests directly, no success. Nothing seems to make it work.

Oddly enough, the index view on the same controller which uses a simplePaginate works fine. The form is built with Laravel Collective forms, could it be omitting the csrf_token and making the request bounce at the request side?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wPh7Jg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire