2

---------- 表 ----------

用户

  • 用户身份

顾客

  • 客户ID
  • 用户身份

时间表

  • schedule_id
  • mail_id
  • 客户ID

邮件

  • mail_id
  • 主题

- - - - - 楷模 - - - - -

schedules_model

public function customer() 
{
    return $this->belongsTo('App\Customer', 'customer_id');
}
public function mail() 
{
    return $this->belongsTo('App\Mail', 'mail_id');
}
public function user() 
{
    return $this->hasOneThrough(?);
}

--------- 控制器 ----------

$schedules = schedules_model->with('customer')->with('mail')->get();

请帮助我如何通过客户获取用户信息?非常感谢您的支持!

4

1 回答 1

1

为什么直接从时间表中获取用户信息,你可以简单地做

$schedules = schedules_model->with('customer.user')->with('mail')->get();
于 2020-02-19T16:41:12.437 回答