left join

$data = Family::query()
    ->columns("*")
    ->leftJoin("FamilyUsers", 'a.family_id = Family.id', 'a')
    ->leftJoin("Users", 'b.id = a.user_id', 'b')
    ->where("a.family_id = $id_family")
    ->execute();

echo '<pre>';
print_r($data -> toArray());
exit;

But I can't get, I want to query data, could you tell me how do I change?


36.3k

Hey man

Do you have namespace in model ?

    query = User::query()
            ->columns(__NAMESPACE__ . '\User.*')
            ->leftJoin(__NAMESPACE__ . '\OrganizationUser', __NAMESPACE__ . '\User.id = ou.idUser', 'ou')
            ->leftJoin(__NAMESPACE__ . '\Organization', 'o.id = ou.idOrganization', 'o')
            ->where('ou.idUser IS NULL')
            ->execute();

        if ($query->count()) {
            return $query;
        }

        return false;