这是我 Laravel 应用程序的代码:
public function sendNotifications()
{
$matchingSubscriptions = DB::table('tournament_match_plan')
->join('push_subscriptions', 'push_subscriptions.age_group', '=', 'tournament_match_plan.league')
->where('tournament_match_plan.start', '=', '11:20:00')
->where('tournament_match_plan.team_1', '=', 'push_subscriptions.club')
->orwhere('tournament_match_plan.team_2', '=', 'push_subscriptions.club')
->get();
dd($matchingSubscriptions);
}
这是调试结果:
IlluminateSupportCollection {#751 ▼ // appHttpControllersGuestsGuestsPushController.php:97
#items: []
#escapeWhenCastingToString: false
}
为什么我的 Laravel 代码没有结果?
我在 PhpMyAdmin 中尝试了相同的查询:
SELECT * FROM tournament_match_plan JOIN push_subscriptions ON push_subscriptions.age_group = tournament_match_plan.league WHERE tournament_match_plan.start = '11:20:00' AND (tournament_match_plan.team_1 = push_subscriptions.club OR tournament_match_plan.team_2 = push_subscriptions.club);
使用这个查询我得到了一个结果,并且是正确的。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
以下是工作代码。
$matchingSubscriptions = DB::table('tournament_match_plan') ->join('push_subscriptions', 'push_subscriptions.age_group', '=', 'tournament_match_plan.league') ->where('tournament_match_plan.start', '=', '11:20:00') ->where(function ($query) { $query->where('tournament_match_plan.team_1', '=', DB::raw('push_subscriptions.club')) ->orWhere('tournament_match_plan.team_2', '=', DB::raw('push_subscriptions.club')); }) ->get();