Search code examples
phpmysqllaravel-5.3

Pagination functionality in laravel, Issue: Call to a member function paginate() on array


Laravel Framework - using version 5.4: If I used raw query as shown below in User.php controller and making paginate(3) as shown below. But it is giving error as "Call to a member function paginate() on array". solution please.

DB::select("select u.email,u.name,u.created_at from users u where u.id in (select max(ui.id) from users ui where ui.status = 0) order by ui.id desc")->paginate(3);

Solution

  • This code will do the job

     DB::table('users as u')->select(['u.email','u.name','u.created_at'])->whereRaw("u.id in (select max(ui.id) from users ui where ui.status = 0)")->orderBy("ui.id","desc")->paginate(3);