【问题标题】:Laravel Many to Many eager loadingLaravel 多对多急切加载
【发布时间】:2014-03-14 16:44:21
【问题描述】:

我正在尝试隐藏关于多对多关系的列,但目前没有成功。 我有:

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

有人请,还有其他解决方案吗?

【问题讨论】:

    标签: php laravel laravel-4 eloquent


    【解决方案1】:

    是的,在您的模型上,您希望保持隐藏的任何列都应添加到隐藏数组中。

    protected $hidden = array('password');
    

    【讨论】:

    • 但在另一种情况下我不需要隐藏..我如何动态更改?
    猜你喜欢
    • 2021-12-01
    • 2015-05-13
    • 2016-06-06
    • 1970-01-01
    • 2019-08-09
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多