Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

X-Mac's avatar
Level 1

Use union in a query

Hi there, I'm trying to create a query with union this are my query: $code = DB::table('articles') ->leftjoin('aliquoteiva', 'vat_id', '=', 'serial') ->where('code', 'like', '%'.$nome.'%') ->where('company_id',$company_id) ->get();

        $articles = DB::table('articles')
            ->leftjoin('aliquoteiva', 'vat_id', '=', 'serial')
             ->where('article', 'like', '%'.$nome.'%')
             ->where('company_id',$company_id)
             ->union($code)
             ->get();

but when I try to show $articles I got this error message: BadMethodCallException Method getBindings does not exist.

0 likes
3 replies
staudenmeir's avatar

You have to remove ->get() from the $code query.

4 likes
X-Mac's avatar
Level 1

it' s work thanks staudenmeir

Please or to participate in this conversation.