Create pagination for mutil language
Created 7 years ago by buinguyentuong

I have url: http://dev.p16063.dsquare.vn/en/news/new-event?page=3. When I click next page then url format http://dev.p16063.dsquare.vn/news/new-event?page=4. Can't get locale 'en' for button pagination. I have used {{ listpost.links() }} or {{ listpost.render() }} but not work. Thanks You.

keevitaja  —  7 years ago

I cannot get pagination working at all. The query works with simple ->get() but if i try to use ->paginate() i get error:

QueryException in Connection.php line 764:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause' (SQL: select count(*) as aggregate from `horses_classifieds_adverts` where exists (select * from `horses_classifieds_types` where `horses_classifieds_adverts`.`type_id` = `horses_classifieds_types`.`id` and `slug` = horses and `horses_classifieds_types`.`deleted_at` is null) and exists (select * from `horses_classificators_keywords` inner join `horses_classifieds_adverts_keywords` on `horses_classificators_keywords`.`id` = `horses_classifieds_adverts_keywords`.`related_id` where `horses_classifieds_adverts_keywords`.`entry_id` = `horses_classifieds_adverts`.`id` and `slug` = sale and `horses_classificators_keywords`.`deleted_at` is null) and (`name` like %et% or `description` like %et%) and `horses_classifieds_adverts`.`deleted_at` is null)

And this is the query:

    public function filter($type, $keywords = [], $filter = null)
    {
        $query = $this->model;

        $query = $query->whereHas('type', function($query) use($type) {
            $query->where('slug', $type);
        });

        foreach ($keywords as $keyword) {
            $query = $query->whereHas('keywords', function($query) use($keyword) {
                $query->where('slug', $keyword);
            });
        }

        if ($filter) {
            $query = $query->where(function($query) use($filter) {
                $query = $query->where('name', 'like', '%'.$filter.'%')
                    ->orWhere('description', 'like', '%'.$filter.'%');
            });
        }

        return $query;
    }

Please do not, that name and description are translated fields!