Can anyone help me to get the data .
$ticketList = Ticket::with('appliance', 'brand')->get();
$userAppliances = DB::table('user_appliances')
->where('user_id', 5)
->pluck('appliance_id')
->toArray();
$userBrands = DB::table('user_brands')
->where('user_id', 5)
->pluck('brand_id')
->toArray();
$ticketList = $ticketList->map(function ($ticket) use ($userAppliances) {
return $ticket->where($ticket->appliance_id,'=', $userAppliances);
});
dd($ticketList);
它回傳了集合。我想要所有票證,其中票證->brand_id 和 tickt->appliance_id 包括 {我從 userBrands 和 userAppliances 獲得的所有 id}。我在撰寫查詢時遇到問題
uj5u.com熱心網友回復:
試試這個
$userBrands = DB::table ('user_brands')
->where('user_id', 5)
->pluck('appliance_id')
->toArray();
$ticketList = Ticket::with('appliance', 'brand')
->where(function($query) use ($userBrands){
$query->whereIn('appliance_id', $userBrands);
})->get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/376023.html
