I am having an issue in selecting specific fields from multiple tables using unionAll()
in laravel 5.2.
This is an example of what I am doing:
$test1 = \DB::table('test1')->select('test1.first as example', 'test1.timestamp')->orderBy('timestamp', 'desc');
$test2 = \DB::table('test2')->select('test2.second as example2', 'test2.timestamp')->orderBy('timestamp', 'desc');
$test3 = \DB::table('test3')->select('test3.third as example3', 'test3.timestamp')->orderBy('timestamp', 'desc');
$testArray = $test1->unionAll($test2)->unionAll($test3)->get()->toArray();
So in this example it would return an array with a bunch of results, the issue comes in when the array is created.
The key for every sub array is going to be example, rather than example for the first table results, example2 for second table results and example3 for third table results.
I need it returned with valid keys such as:
[{"example: test1", "timestamp: 11-22-33"}{"example2: test2", "timestamp: 11-22-33"}{"example3: test3", "timestamp: 11-22-33"}]
But as I said, my union statements seem to be returning only the first example and timestamp keys for all sub arrays like this:
[{"example: test1", "timestamp: 11-22-33"}{"example: test2", "timestamp: 11-22-33"}{"example: test3", "timestamp: 11-22-33"}]