select
"workshop_instance_visit".*,
"workshop_instance_visit"."customer_id" as "workshop_instance_visit_customer_id",
"cwi"."customer_id"
from "workshop_instance_visit"
inner join "workshop_session" as "ws" on "workshop_instance_visit"."workshop_session_id" = "ws"."workshop_session_id"
right join "customer_workshop_instance" as "cwi" on "cwi"."workshop_instance_id" = "ws"."workshop_instance_id"
where "workshop_instance_visit"."workshop_session_id" = 'b57649c6-81ea-4f4c-bfa4-f91e2aed9ff3'
$query = WorkshopInstanceVisit::query();
//Для конретного кружка делаем запрос
$query->where("workshop_instance_visit.workshop_session_id", "b57649c6-81ea-4f4c-bfa4-f91e2aed9ff3");
$query->select(
'workshop_instance_visit.*',
'workshop_instance_visit.customer_id as workshop_instance_visit_customer_id',
'cwi.customer_id'
);
$query->join('workshop_session AS ws', 'workshop_instance_visit.workshop_session_id', '=', 'ws.workshop_session_id');
// $query->leftJoin
$query->rightJoin('customer_workshop_instance AS cwi','cwi.workshop_instance_id', '=', 'ws.workshop_instance_id');
$worksshopInstanceVisits = $query->get();
//Laravel
$query = WorkshopInstanceVisit::query();
$query->join('workshop_session AS ws', 'workshop_instance_visit.workshop_session_id', '=', 'ws.workshop_session_id')
->leftJoin('customer_workshop_instance AS cwi', function ($join) {
$join->on('cwi.workshop_instance_id', '=', 'ws.workshop_instance_id');
});