0

Error: Call to a member function union() on int

$category = Category::select('name')->count();
$city = City::select('city')->count();
$client = Client::select('name')->count();

$property = Property::select('name')->count()
                    ->union($category)
                    ->union($city)
                    ->union($client)
                    ->get();

dd($property);
IGP
  • 14,160
  • 4
  • 26
  • 43
Illyrian
  • 429
  • 4
  • 16

1 Answers1

2

If you just want an array of counts, union won't work for you. Select count(*) from multiple tables

$counts = [
    'city' => City::count(),
    'category' => Category::count(),
    'client' => Client::count(),
    'property' => Property::count(),
];

There's no need to keep it in one query.

IGP
  • 14,160
  • 4
  • 26
  • 43