[英]Laravel Many to Many eager loading
我正在尝试隐藏多对多关系的专栏,但目前没有成功。 我有:
Square.php
public function sitesquares() {
//Trying to use select() but no success
return $this->belongsToMany('Sitesquare', 'square_site', 'square_id', 'site_id')->select( array('square_id','site_id', 'sites.site_name') );
}
Sitesquare.php
public function squares()
{
return $this->belongsToMany('Square', 'square_site');
}
方形控制器
$sites = Square::with(array('sitesquares'=>function ($q)
{
$q->select(array('site_name')); //also don't work
}))->get();
return $sites; //json
有人请问,还有其他解决方法吗?
是的,在您的模型上,您希望保持隐藏状态的任何列都应添加到隐藏数组中。
protected $hidden = array('password');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.