laravel错误无法转换为字符串

时间:2017-05-31 10:38:08

标签: php laravel-5

我正在使用Laravel 5.2并遇到问题。

我的代码是;

$sts = STSMember::find($member_id)->join('rating', 's_t_s_members.member_id', '=', 'rating.member_id');

但是我收到以下错误

  

类Illuminate \ Database \ Eloquent \ Builder的对象无法转换为字符串'。

如何从两个表中获取member_id?

1 个答案:

答案 0 :(得分:0)

find返回一个模型实例,您需要:

STSMember::where("id","=",$member_id)->join('rating', 's_t_s_members.member_id', '=', 'rating.member_id')->get();

理想情况下:

class STSMember extends Model {
      //Other model code

      public function rating() {
             return $this->belongsTo(Rating::class);
      }
}

然后你可以这样做:

 STMember::with("rating")->find($member_id);

检查https://laravel.com/docs/5.4/eloquent-relationships