在编写查询时遇到问题 laravel

Getting trouble in writing query laravel

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);

它返回了集合。我想要所有门票,其中 ticket->brand_id 和 tickt->appliance_id 包括{我从 userBrands 和 userAppliances 获取的所有 ID}。我在编写查询时遇到问题

试试这个

$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();