Hi @alnouirah
The UNION operator is used to combine the [result-set] of two or more SELECT statements.
Your UNION operator should follow the following conditions:
- Every SELECT statement within UNION must have the same number of columns
- The columns must also have similar data types
- The columns in every SELECT statement must also be in the same order
You are trying to add union in your model which will work on first collection and it will not work in your case even if you use MySQL statement because you are looking for multiple results.
You may use union after get() like following:
$source = $wallet->sourceTransactions();
$my_transaction = $wallet->targetTransactions()->union($source)->get();
dd($my_transaction);
Ref: SQL UNION Operator