1 year ago

Merging two queries with eloquent

Posted 1 year 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);                

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);

    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: help is very much appreciated

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