陣沒有人有任何想法NULL結果,爲什麼這個查詢會產生一些NULL結果(陣列):從雄辯查詢
$events = $this->event
->with('delegates', 'course')
->where('start_date', '<=', $today)
->where('active', '1')
->where('event_status_id', '!=', '3')
->hasCosts()
->has('delegates')
->get()
->map(function($event) {
foreach ($delegates = $event->delegates()->has('contact')->get() as $delegate) {
$account = $delegate->contact->account;
return [
'company' => $account->company_name,
'income' => $account->income($delegates),
'profit' => $account->profit($event, $delegates),
'event' => $account->eventDetails($event, $delegates)
];
}
})
->toArray();
我走進「的foreach」循環和傾倒的ID爲每個事件,帳戶,聯繫人和委託,並且沒有NULL結果。我也沒有收到任何錯誤。
當我轉儲$ events變量我收到這樣的輸出:
array(8) {
[0] NULL
[1] array(4) {
["company"] "Razorfish"
["income"] 523
["profit"] "69.29"
["event"] "ITIL® Service Transition Apr 7, 2014 in London (141)"
}
[2] array(4) {
["company"] "European Central Bank - Europa ECB"
["income"] 1332
["profit"] "137.33"
["event"] "ITIL® Service Offerings & Agreements Apr 7, 2014 in London (142)"
}
[3] array(4) {
["company"] "Knowledge Pool - KP delegates"
["income"] 475
["profit"] "-111.75"
["event"] "ITIL® Foundation Apr 7, 2014 in Leeds (143)"
}
[4] array(4) {
["company"] "Plan International/ Plan UK"
["income"] 537
["profit"] "118.43"
["event"] "ITIL® Foundation Apr 14, 2014 in London (144)"
}
[5] array(4) {
["company"] "Cell Therapy Catapult (part of Guy's hospital)"
["income"] 550
["profit"] "-114.75"
["event"] "ITIL® Service Design Apr 14, 2014 in London (145)"
}
[6] array(4) {
["company"] "European Central Bank - Europa ECB"
["income"] 597
["profit"] "69.80"
["event"] "BCS Specialist Certificate in Supplier Management Apr 14, 2014 in London (146)"
}
[7] array(4) {
["company"] "C Hoare & Co (hoares bank)"
["income"] 523
["profit"] "97.71"
["event"] "ITIL® Continual Service Improvement Apr 23, 2014 in London (148)"
}
}
公告第一個NULL結果。這僅僅是輸出的一個樣本,但在實際輸出中有這樣的結果。
對於初始查詢簡潔的hasCosts()方法是查詢範圍功能:
public function scopeHasCosts($query)
{
return $query->where('tutor_cost', '>', 0)
->orWhere('exam_cost', '>', 0)
->orWhere('material_cost', '>', 0)
->orWhere('venue_cost', '>', 0)
->orWhere('notional_cost', '>', 0)
->orWhere('buy_price', '>', 0);
}
這就是它的一部分。我有代表,但如果他們沒有聯繫人,他們就會鏈接到一個名爲「未知」的表格,然後這些未知數據鏈接到帳戶,儘管其中一些沒有帳戶。查看下面的答案,看看我是如何解決它的。 –