How to use laravel pagination with query builder

不羁岁月 提交于 2019-12-12 04:46:32

问题


I am using laravel pagination but it is not working with query builder i have also refer the every answer of below stack url but it is also not working every answer showing a new error.Please help me to resolve this problem how i can used pagination with laravel query builder.I am using 5.3 version of laravel. Stack referal link=Laravel 5 Pagination with Query Builder

 public function ajaxPagination(Request $request)

{

    $query="SELECT users.`id`,users.`email`,users.`u_firstname`,users.`u_lastname`,users.`u_dob`,users.`u_mobile`,user_roles.`ur_role_id`,UCASE(master_roles.`role_name`) as roles,case users.`u_status` when '0' then 'Inactive' when '1' then 'Active' when '4' then 'Deactivate' end as status FROM `users` inner join user_roles on user_roles.`ur_user_id`=users.`id` inner join master_roles on user_roles.`ur_role_id`=master_roles.`role_id` where users.`id`!='$id' and users.`u_status`!='3' order by users.`id` desc";

     $items = DB::select(DB::raw($query))->paginate(20);

     var_dump($items);
    die;
    if ($request->ajax()) {

        return view('data', compact('items'));

    }

    return view('items',compact('items'));

}

Error while using the above code Call to a member function paginate() on array

来源:https://stackoverflow.com/questions/46117885/how-to-use-laravel-pagination-with-query-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!