我有兩個不同的laravel查詢,我想基於第一個查詢使用whereNotIn
第二個查詢。但whereNotIn
似乎不工作,因爲數據仍然顯示。laravel where不在工作
這第一個查詢
$detailservice = DetailServiceOrder::leftJoin('services', 'detail_service_orders.service_id', '=', 'services.id')
->select('detail_service_orders.*',
'services.service_name')
->where('sales_order_id', $id)
->get();
這第二個查詢
foreach ($detailservice as $data) {
$service[] = Service::whereNotIn('id', [$data->service_id])->get();
}
dd($service);
這裏我dd($service)
結果樣品
#attributes: array:4 [▼
"id" => 2
"service_name" => "Mail Service"
"created_at" => "2016-11-26 02:15:24"
"updated_at" => "2016-11-26 02:15:24"
]
#attributes: array:4 [▼
"id" => 1
"service_name" => "Network Maintenance"
"created_at" => "2016-11-15 07:00:45"
"updated_at" => "2016-11-15 07:00:45"
]
這裏我dd($detailservice)
結果樣品
#attributes: array:10 [▼
"sales_order_id" => 6
"service_id" => 1
"order_type" => "add"
"select_plan" => "test 1"
"qty" => 2
"unit_price" => 200.0
"note" => "testing 1"
"updated_at" => "2016-12-22 01:34:00"
"created_at" => "2016-12-22 01:34:00"
"service_name" => "Network Maintenance"
]
#attributes: array:10 [▼
"sales_order_id" => 6
"service_id" => 2
"order_type" => "change"
"select_plan" => "test 2"
"qty" => 3
"unit_price" => 400.0
"note" => "testing 2"
"updated_at" => "2016-12-22 01:34:00"
"created_at" => "2016-12-22 01:34:00"
"service_name" => "Mail Service"
]
以上dd($service)
結果不應顯示,因爲它已在第二個查詢上過濾。
這是什麼'DD($ detailservice);'說明了什麼? –
嗨,我編輯我的問題添加'dd($ detailservice)' – rafitio
謝謝。請檢查下面的答案。 –