Laravel比较不同表中的三列返回0个项目



我是Laravel的新手,我想比较两个不同表的三列,数据数字与点(4.3,6.00,30.40(。我有这个逻辑,但它返回 0(无项目(。知道为什么吗?

public function index()
{        
$tips = DB::table('tips')->where('status','1')->get();
foreach($tips as $tip){
$eventHome[] = $tip->home;
$eventDraw[] = $tip->draw;
$eventAway[] = $tip->away;
}
$events = DB::table('apidata')
->where('oddsHome','=', $eventHome)
->where('oddsDraw','=', $eventDraw)
->where('oddsAway','=', $eventAway)
->get();   
dd($events);
}

我使用上面的代码在我的刀片中替换此代码:

@foreach($events as $event)
@foreach ($tips as $tip)
@if($event->eventHome == $tip->home
and $event->eventDraw == $tip->draw
and $event->eventAway == $tip->away)
@endforeach
@endforeach

提前感谢!

使用php artisan tinker来测试代码中的每个查询。

在 tinker 中,如果结果不为 null,则写DB::table('tips')->where('status','1')->get();,因此使用上一个常量(自定义(值进行下一个查询:

DB::table('apidata')
->where('oddsHome','=', 4.3)
->where('oddsDraw','=', 6.00)
->where('oddsAway','=', 30.40)
->get();

如果结果仍然为空,则肯定没有具有确切数字的数据。 如果为不为空,则模型中可能存在问题。 例如,未定义"主页"或"绘图"。

要获得更多帮助,您必须在数据库中共享模型和一些数据。

最新更新