Hi everyone how are you, i hope you’ll well.
Well i am making a web site in my job and i have a trouble.
This is my code :
this is what i want to do, in Mysql ( PHPMyADmin) it works with no problems, look:
SELECT * from tipo_usuarios INNER JOIN users ON tipo_usuarios.id=users.id AND tipo_usuarios.jerarquia="Administrador";

Well this is my eloquent Code in laravel, it works too BUT, only with ID’s i dont how to add the " AND " in eloquent.
$visitas = User::join("visitas","visitas.id_usuario", "=", "users.id")
->select("*")
->get();

I hope you can help me with that little trouble 🙂
>Solution :
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
Eloquent relationship