Выход из измененного кода:
A() C-tor
A() C-tor
B() C-tor
~B() D-tor
~A() D-tor
~A() D-tor
Мне удалось это исправить, сначала запросив мои данные, прежде чем выбрать подзапрос. Я также добавил ROUND()
к запросу, чтобы остановить null
совпадения и округлить значение до ближайшего 10.
$stars = DB::table('product_reviews')->selectRaw('ROUND(AVG(stars))')
->whereColumn('product_id', 'product_list.id');
$product = DB::table('product_list')->join('product_categories', 'product_list.product_category', '=', 'product_categories.id')
->select('*')
->selectSub($stars, 'stars_avg')
->join('product_types', 'product_list.product_type', '=', 'product_types.id')
->where('product_list.id', (int) $productId)
->take(1)
->get()
->first();
Это теперь дает мне желаемый результат:
{#634 ▼
+"id": 3
+"cost": "150.00"
+"product_category": 1
+"product_type": 3
+"product_score": 0
+"created_at": "2019-01-16 16:34:29"
+"updated_at": "2019-01-16 16:34:29"
+"rating": 0
+"down_payment": "10.00"
+"title": "Static"
+"price_start": "50.00"
+"price_stop": "150.00"
+"theme": "Custom"
+"pages": 4
+"rbac": 0
+"portal": 0
+"external_software": 0
+"company_supplier": "Iezon Solutions"
+"stars_avg": "5"
}