doujin8673 2019-03-16 20:21
浏览 29

从两张表Eloquent Laravel不在哪里

I have table: User, Certification, Waybill and user_certification and waybill_certification.

I want create query using Eloquent where i check that user have certification which checked in waybill

$check = \App\User::with('certification', 'waybill.certification')->

And i dont now what now, is is possible?

I have create relationship in models

Waybill

  public function certification() {
    return $this -> hasMany('App\WaybillCertification');
  }

  public function user() {
    return $this -> belongsTo('App\User');
  }

User

public function waybill() {
  return $this -> hasMany('App\Waybill');
}

public function certification() {
  return $this -> hasMany('App\UserCertification');
}

I know i could use query builder for it but i would like learn how do it with eloquent.

Recently i used mysqli_query Code:

    $sql = mysqli_query($conn, "SELECT c.ID
    FROM request_certification rc
    INNER JOIN certifications c
    ON rc.ID_certification = c.ID
    WHERE rc.ID_request = '$requestID'
    AND rc.ID_certification NOT IN (
      SELECT c.ID
      FROM certifications c
      INNER JOIN user_certification uc ON uc.certification_id = c.ID
      WHERE user_ID = $userID)");

  if(mysqli_num_rows($sql) > 0) {
    return true;
  } else {
    return false;
  }
}

Thanks for help you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?