Desory
5 months ago

Merging two queries with eloquent

Posted 5 months ago by Desory

i am currently stuck on merging querys. I hope somebody can help me

ive got this query :

        //book id gets dynamically requested
        $book_id = 2;
        $ads = Ad::
        whereHas('book', function ($query) use ($book_id) {           
                $query->where('book_id', $book_id);                
        })->paginate(30);

in one function and in another function ive got this:

    $checkbox = $request->input('checkedIds');
    $serviceQuery = Ad::whereHas('authors', function ($query) use ($checkbox) {
        $query->whereIn('ad_service.author_id', $checkbox);
    })
        ->get();

    return $serviceQuery;

and now i wanted to use function 2 in function 1 and merge, so the result $ads is a query which combines the 2 of them. However, even though i found this post i cannot manage to do it: https://laracasts.com/discuss/channels/general-discussion/merging-two-complex-eloquent-queries help is very much appreciated

Please sign in or create an account to participate in this conversation.