我在ConfigServiceProvider
中运行查询以设置我想在整个应用程序中使用的计数值。
public function boot() {
$query = "SELECT count(*) FROM property_in_property_category INNER JOIN property ON property_in_property_category.property_id = property.id INNER JOIN business ON property.business_id = business.id WHERE property_in_property_category.property_category_id = 1 AND property.active = 1 AND business.isActive = 1";
$sale = DB::select($query);
foreach($sale as $object) {
$sale_array[] = (array) $object;
}
$query = "SELECT count(*) FROM property_in_property_category INNER JOIN property ON property_in_property_category.property_id = property.id INNER JOIN business ON property.business_id = business.id WHERE property_in_property_category.property_category_id = 2 AND property.active = 1 AND business.isActive = 1";
$rent = DB::select($query);
foreach($rent as $object) {
$rent_array[] = (array) $object;
}
config([
'for-sale' => $sale_array[0]['count(*)'],
'for-rent' => $rent_array[0]['count(*)']
]);
}
当我在phpMyAdmin
中运行查询时,我得到了正确的值,如413和227.
但是当我使用config('for-sale')
和config('for-rent')
在视图中调用这些值时,值不正确,如446和239.这是在Linux服务器上。在本地(Windows)上运行时,它为我提供了正确的值。
首先我认为这可能与名称的大小写有关,但是由于查询在phpMyAdmin中运行良好,并且在其余代码中没有套管,这是不可能的