0

I have two tables. One is Sells Data and another is Bank Deposit Withdraw data. I can show data of sells table. and also can show data of banks. But I want to show the data like this

17 Nov 2017 Sells Data.....
16 Nov 2017 banks Data....
15 Nov 2017 Sells Data.....
15 Nov 2017 banks Data....

but now I get the data like this

15 Nov 2017 Sells Data.....
16 Nov 2017 Sells Data.....

15 Nov 2017 banks Data....
17 Nov 2017 banks Data....

How can I show the data as my desired one

codes:

$sell = Sells::orderBy('id', 'desc')->get();
$bank = Banks::orderBy('id', 'desc')->get();

getting data by this. But cannot show data as I want.

Kapil Paul
  • 446
  • 7
  • 22

1 Answers1

0

if both tables have exact same colums, you can do it with union:

$sells = DB::table('sells')->select('*');
$banks = DB::table('banks')->select('*')
    ->union($sells)
    ->latest()
    ->get();

but if they are not the same, you must select the same colums:

$sells= DB::table("sells")
    ->select("sells.name"
      ,"sells.price"
      ,"sells.created_at");
$banks = DB::table("banks")
    ->select("banks.name"
      ,"banks.price"
      ,"banks.created_at")
    ->unionAll($sells)
    ->orderBy('created_at', 'DESC')
    ->get();
pedram afra
  • 815
  • 6
  • 14