【问题标题】:Eloquent Relationships - hasOneThrough雄辩的关系 - hasOneThrough
【发布时间】:2020-06-03 21:43:42
【问题描述】:

--------- 表格 ----------

用户

  • user_id

客户

  • customer_id
  • user_id

时间表

  • schedule_id
  • mail_id
  • customer_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();

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

【问题讨论】:

    标签: laravel has-one-through


    【解决方案1】:

    为什么直接从日程表中获取用户信息,你可以这样做

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-23
      • 2021-10-02
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2014-08-27
      相关资源
      最近更新 更多