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.