Wrong data type when counting service count
my-idlers V2.3.2
on file app/Models/Home.php
public static function servicesCount()
{
return Cache::remember('services_count', now()->addHours(6), function () {
$count = DB::table('pricings')
->select('service_type', DB::raw('COUNT(*) as amount'))
->groupBy('service_type')
->where('active', 1)
->get();
var_dump($count);
return $count;
});
}
will produce
object(Illuminate\Support\Collection)#1121 (2) { ["items":protected]=> array(2) { [0]=> object(stdClass)#1269 (2) { ["service_type"]=> string(1) "1" ["amount"]=> string(1) "3" } [1]=> object(stdClass)#1282 (2) { ["service_type"]=> string(1) "3" ["amount"]=> string(1) "1" } } ["escapeWhenCastingToString":protected]=> bool(false) }
notice that the service_type is string
while on the same file
public static function doServicesCount($services_count): array
{
$services_count = json_decode($services_count, true);
return Cache::remember('services_count_all', now()->addWeek(1), function () use ($services_count) {
$servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
foreach ($services_count as $sc) {
$total_services += $sc['amount'];
if ($sc['service_type'] === 1) {
$servers_count = $sc['amount'];
} else if ($sc['service_type'] === 2) {
$shared_count = $sc['amount'];
} else if ($sc['service_type'] === 3) {
$reseller_count = $sc['amount'];
} else if ($sc['service_type'] === 4) {
$domains_count = $sc['amount'];
} else if ($sc['service_type'] === 5) {
$other_count = $sc['amount'];
} else if ($sc['service_type'] === 6) {
$seedbox_count = $sc['amount'];
}
}
return array(
'servers' => $servers_count,
'shared' => $shared_count,
'reseller' => $reseller_count,
'domains' => $domains_count,
'other' => $other_count,
'seedbox' => $seedbox_count,
'total' => $total_services
);
});
}
it is try to match exact type of int value, this result in empty (0) value on Home page....
the same goes for breakdownPricing() in the same file
on file resources/views/home.blade.php
also require to change to @if(Session::get('timer_version_footer', 0) == 1) as the type didnt match
@AhmadShamli
Im not getting the string type when debugging and the counts work as expected, interested to see if others get this issue:
= Illuminate\Support\Collection {#5611 all: [ {#5609 +"service_type": 1, +"amount": 1, }, {#5605 +"service_type": 2, +"amount": 1, }, {#5607 +"service_type": 3, +"amount": 1, }, {#5606 +"service_type": 4, +"amount": 1, }, ], }
HI,
below would be the server information:
Host: Namecrane (BuyShared) server: lv-shared01.dapanel.net php: php 8.1.28 loaded ext: Array ( [0] => Core [1] => date [2] => libxml [3] => openssl [4] => pcre [5] => sqlite3 [6] => zlib [7] => bz2 [8] => calendar [9] => ctype [10] => curl [11] => hash [12] => filter [13] => ftp [14] => gettext [15] => json [16] => iconv [17] => SPL [18] => pcntl [19] => readline [20] => Reflection [21] => session [22] => standard [23] => mbstring [24] => shmop [25] => SimpleXML [26] => tokenizer [27] => xml [28] => litespeed [29] => i360 [30] => bcmath [31] => dom [32] => fileinfo [33] => gd [34] => imagick [35] => intl [36] => exif [37] => mysqlnd [38] => mysqli [39] => PDO [40] => pdo_mysql [41] => pdo_sqlite [42] => Phar [43] => posix [44] => soap [45] => sockets [46] => sodium [47] => xmlreader [48] => xmlwriter [49] => xsl [50] => zip )