2
我正在使用laravel 5.2。我的数据库设置为:有没有办法在laravel 5.2中使用雄辩的一对多关系来选择列?
social_logins
ID | social_id | provider
-----------------------------
1 | x | twitter
2 | y | facebook
3 | z | twitter
twitter_data
ID | social_id | some_value | another_value
-----------------------------------------------
1 | x | 100 | 600
2 | y | 200 | 100
3 | z | 100 | 400
我对模型设置为social_logins关系:
public function twitterData()
{
return $this->hasMany('App\Models\TwitterData', 'social_id', 'social_id');
}
在我的控制器我想要检索回某些列的twitter_data与外键social_id。到目前为止,我已经尝试过: $ socialLogin-> twitterData-> select('some_value','another_value'); 但我只是得到读取错误:
BadMethodCallException in Macroable.php line 74:
Method select does not exist.
如果我使用一个lists()
调用,比如$socialLogin->twitterData->lists('some_value');
只有一列,我能找回数据,但我怎样才能使它的多个列的工作?
非常感谢阿列克谢奏效! – kevinabraham