Laravel 使用仅选定列的分页? [英] Laravel using paginate with only selected columns?

查看:12
本文介绍了Laravel 使用仅选定列的分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 laravel 中使用 paginate ,但现在我想使用 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);

这是我试图通过 paginate 获得的 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);

但它对我不起作用?

推荐答案

这就是你所需要的:

// QueryBuilder
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆