I am making a website in my job and I have an issue.
This is what I want to do; in MySQL
(PHPMyAdmin
) it works with no problems:
SELECT *
FROM tipo_usuarios
INNER JOIN users
ON tipo_usuarios.id = users.id AND
tipo_usuarios.jerarquia = "Administrador";
Well this is my Eloquent in Laravel, it works but only with IDs. I don't know how to add AND
in Eloquent.
$visitas = User::join("visitas", "visitas.id_usuario", "=", "users.id")
->select("*")
->get();
CodePudding user response:
You can use function for second argument in join
$visitas = User::join("visitas", function ($join) {
$join->on("visitas.id_usuario", "=", "users.id")
->on("visitas.jerarquia","=","Administrador")
})
->select("*")
->get();
However, you should read the documentation for creating Eloquent relationship. This is a more convenient and understandable functionality than using the query builder