paginate query with unionall() not working in laravel with sqlsrv

15 views Asked by At

i've this query

$courses = DB::table('courses')
            ->where('courses.name', 'like', '%'.$search_text.'%')
            ->selectRaw(
                "id, courses.name as name, courses.created_at as created_at,
                (CASE
                    WHEN courses.is_program = 1 THEN 'Program'
                    WHEN courses.is_program = 0 THEN 'Course'
                    ELSE 'Unknown'
                END) AS type"
            );

        $surveys = DB::table('surveys')
            ->where('surveys.name', 'like', '%'.$search_text.'%')
            ->selectRaw(
                "id, surveys.name as name, surveys.created_at as created_at,
                 (CASE
                    WHEN surveys.id != 0 THEN 'Survey'
                    ELSE 'Unknown'
                END) AS type"
            );

        $exhibitions = DB::table('exhibitions')
            ->where('exhibitions.name', 'like', '%'.$search_text.'%')
            ->selectRaw(
                "id, exhibitions.name as name, exhibitions.created_at as created_at,
                 (CASE
                    WHEN exhibitions.id != 0 THEN 'Exhibition'
                    ELSE 'Unknown'
                END) AS type"
            );

        $results = $courses->unionAll($surveys)->unionAll($exhibitions);
        if ($perPage) {
            $results = $results->paginate($perPage);
        } else {
            $results = $results->get();
        }

        return $results;

the pagination working good with mysql but with sqlsrv not working all data returned any one can help please

i tried to use merge bindings and sub quires but without any updates

0

There are 0 answers