本文介绍了Laravel查询构建器:选择除少数几个以外的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Laravel查询构建器,可以很容易地使用->select()
选择或别名字段.
With the Laravel query builder, it is easy to select or alias fields with ->select()
.
如何选择除少数几个字段以外的所有字段?
例如,我希望永远不要将记录的id
返回到前端.
How do I select all fields except for a few?
For example, I wish never to return the id
of my record back to the front end.
推荐答案
http://laravel.com/docs/4.2/eloquent
如果您仍然不介意从技术上选择它们,则可以从Laravel的默认数组/JSON转换中抑制字段:
If you don't mind still technically selecting them, you can suppress fields from Laravel's default array/JSON conversion:
class User extends Eloquent {
protected $hidden = ['password', 'id', ...];
}
这篇关于Laravel查询构建器:选择除少数几个以外的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!