Eloquent 远程多对多该如何快速获取数据?
教程中提到远程一对多,可直接获取数据。
对于远程多对多该如何处理呢?
比如:
class User
{
// 用户标签
public function labels()
{
return $this->belongsToMany('App\Models\CustomerLabel', 'customer_label_relations', 'user_id', 'customer_label_id');
}
}
class CustomerLabel extends Model
{
// 用户
public function users()
{
return $this->belongsToMany('App\User', 'customer_label_relations', 'customer_label_id', 'user_id');\
}
}
class CustomerFunction extends Model
{
public function labels()
{
return $this->belongsToMany('App\Models\CustomerLabel', 'customer_label_functions', 'customer_function_id', 'customer_label_id');\
}
}
如何快速获取某个$user的相关的CustomerFunction呢?
推荐文章: