hyperf關聯模型條件查詢

冯元春發表於2024-12-07
  $query = Amodel::query();;
        $query->with("user");

        if (isset($params['username']) && filled($params['username'])) {
            $username = $params["username"];
            $query->whereHas("user", function ($query) use ($username) {
                $query->where('username', $username);
            });
        }

Amodel 關聯user 查詢條件需要查user表的username

相關文章