【发布时间】:2014-06-30 00:05:35
【问题描述】:
当我使用 eloquent 时,我可以使用“where”方法,然后使用“get”方法来填充包含我在数据库中选择的对象的对象。 我的意思是:
$users = User::where('gender', 'M')->where('is_active', 1)->get(['pseudo', 'email', 'age', 'created_at'])->toArray();
在这里我可以选择我想要的列,例如“伪”、“电子邮件”等。 但是我在 laravel doc 中错过的是相反的方法。 可能是这样的:
$users = User::where('gender', 'M')->where('is_active', 1)->notGet(['pseudo', 'email', 'age', 'created_at'])->toArray();
感谢您对未来的回答,祝您有美好的一天。
【问题讨论】:
-
问题是,你为什么要这么做?使用 ORM 你宁愿不这样做,如果你只是不想显示某些列,还有其他方法可以实现。
-
我问它是因为当您有 15 列并且想要 13 列时,执行类似 ->notGet(['column14', 'column15']); 之类的操作可能会更快。而不是 ->get(['column1', 'column2', [...], 'column13']);。你看到了吗?