Laravel仅对选定的列使用分页吗? [英] Laravel using paginate with only selected columns?
本文介绍了Laravel仅对选定的列使用分页吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何在laravel中使用分页, 但是现在我想使用paginate() 仅与选定的列一起使用. 这是我的分页代码:
I know how to use paginate in laravel , but now I want use paginate() with selected columns only . this is my pagination code:
$data['users']=DB::table('users')->paginate(2);
这是我试图通过分页获取的sql语句.
this the sql statement I'm trying to get with paginate.
select id,name,username,email,groupName,lastSignIn from users;
此选择语句的我的laravel代码:
my laravel code for this select statement:
$data['users']=DB::select('select id,name,username,email,groupName,lastSignIn from users;')->paginate(4);
但是它不能和我一起工作吗?
but it's not working with me?
推荐答案
这是您需要的:
// Query\Builder
DB::table('users')
->select('id', 'name', 'username', 'email', 'groupName', 'lastSignIn')
->paginate(4);
这:
DB::select(...);
是另一个类(Connection
)的完全不同的方法.
is completely different method of another class (Connection
).
这篇关于Laravel仅对选定的列使用分页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文