Ad

Pagination Not Working In Laravel 5.1

I am trying to set pagination in Laravel 5.1, here is what I am trying to do:

$bridal_requests_data = \DB::table('bridal_requests')->leftJoin('audiences', function($join) {
                        $join->on('bridal_requests.id', '=', 'audiences.request_id');
                        })
                        ->orderBy('bridal_requests.id', 'DESC')->paginate('15', array('bridal_requests.*'));

it is giving the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) as aggregate from bridal_requests left join audiences on bridal_requests' at line 1 (SQL: select count(bridal_requests.*) as aggregate frombridal_requestsleft joinaudiencesonbridal_requests.id=audiences.request_id`)

As stated above, it is not working for bridal_requests.*, but if I use brial_requests.id then it works, but I need to use get all data from bridal_requests table.

Ad

Answer

You should use:

$bridal_requests_data = \DB::table('bridal_requests')->select('bridal_requests.*')->leftJoin('audiences', function($join) {
                        $join->on('bridal_requests.id', '=', 'audiences.request_id');
                        })
                        ->orderBy('bridal_requests.id', 'DESC')->paginate(15);
Ad
source: stackoverflow.com
Ad