标签:
1.model里面设置
protected $hidden = [‘password‘];//要屏蔽的字段
2.model里面设置
protected $visiable = [‘name‘];//要显示的字段
3.查询的时候用distinct,指定要显示的字段
XX::distinct([你要显示的字段]);
4.查询的时候在get或first指定要显示的字段
XX::get([你要显示的字段]);
在查询语句加上->with(‘你relationship函数的名字‘);
这个是我自己遇到的问题,因为你取到数据后,不可以再使用first()等这些builder的方法定义输出字段,那会重新进行数据库查询,可以考虑
新建一个子model
class BoyJson extends \Eloquent { protected $table = "boys"; protected $hidden = [‘user_id‘, ‘updated_at‘]; protected $fillable = [ ‘id‘, ‘text‘, ‘img_path‘];//把你想输出的字段加上 public static function extract(Boy $s) { $res = new BoyJson(); $res->fill($s->toArray()); return $res; } }
这样的好处是结构清晰,写起来简单,但是感觉太麻烦了点,哪位大神知道有什么现场的函数还求指点,找了api文档没找到。
希望能帮助到谁
自己建的一个群,希望广结英豪,尤其是像我一样脑子短路不用react硬拼anroid、ios原生想干点什么的朋友。
App独立开发群 533838427
标签:
原文地址:http://www.cnblogs.com/matoo/p/5212594.html