【发布时间】:2022-01-11 13:41:11
【问题描述】:
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}。我在编写查询时遇到了麻烦
【问题讨论】:
-
不要使用 map 函数,而是使用 leftJoin 并进行一次查询,这样你的所有条件都与 where 原因一致,你肯定会得到所需的数据
标签: laravel database eloquent mapping eloquent-relationship