Laravel根据多对多关系获取物品

时间:2018-05-07 21:25:26

标签: mysql laravel eloquent many-to-many

如何在Laravel Eloquent中查询以下标准

拥有项目,员工表和多对多的binder project_member表,我想获得项目由登录用户作为团队成员所拥有的项目。

在我的项目模型中

/**
 * @return mixed
 */
public function members()
{
    return $this->belongsToMany('App\User', 'project_team', 'id', 'project');
}

和用户表

/**
 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
 */
public function team()
{
    return $this->belongsToMany('App\Project', 'project_team', 'employee', 'project');
}

我想让所有登录用户的项目都是给定项目的成员

0 个答案:

没有答案
相关问题