mmanos / laravel-search

A search package for Laravel 5.
MIT License
352 stars 59 forks source link

pagination not working #18

Closed mouhsinelonly closed 8 years ago

mouhsinelonly commented 9 years ago

Class paginator does not exist

using laravel 5

puskic commented 9 years ago

There is a problem in Query.php with App::make('paginator'). in Laravel 5

I modify paginate method Like this: /* * Execute the current query and return a paginator for the results. * @param int $num * * @return \Illuminate\Pagination\LengthAwarePaginator as Paginator */ public function paginate($num = 15) { //$paginator = App::make('paginator');

    $page = (int) Input::get('page', 1);

    $this->limit($num, ($page - 1) * $num);

    return new Paginator($this->get(), $this->count(), $this->limit, $page, [
        'path'  => \Request::url(),
        'query' => \Request::query(),
    ]); //Paginator::make($this->get(), $this->count(), $num);
}

Can someone modify paginate to work with L5

iveoles commented 8 years ago

Any idea when this can be merged in?

iveoles commented 8 years ago

The above code didn't work for me, I ended up again my own function below to call

...
$result  = self::paginate($query, $per_page = 9, $current_page);
...
}

/**
     * Execute the current query and return a paginator for the results.
     *
     * @param     $query
     * @param int $num
     * @param     $current_page
     *
     * @return Paginator
     */
    public static function paginate($query, $num = 15, $current_page = 1)
    {
        $page = (int) $current_page;

        $query->limit($num, ($page - 1) * $num);

        return new LengthAwarePaginator($query->get(), $query->count(), $num, $page, [
            'path'  => Input::url(),
            'query' => Input::query(),
        ]);
    }
iveoles commented 8 years ago

https://github.com/mmanos/laravel-search/pull/43

Pull request added

dmyers commented 8 years ago

This is now fixed as of the latest release (v1.0.4).