Laravel查询失败,但相同的代码在PhpMyadmin中有效
P粉111627787
P粉111627787 2023-08-15 17:54:08
[MySQL讨论组]
<p>这是我 Laravel 应用程序的代码:</p> <pre class="brush:php;toolbar:false;">public function sendNotifications() { $matchingSubscriptions = DB::table('tournament_match_plan') -&gt;join('push_subscriptions', 'push_subscriptions.age_group', '=', 'tournament_match_plan.league') -&gt;where('tournament_match_plan.start', '=', '11:20:00') -&gt;where('tournament_match_plan.team_1', '=', 'push_subscriptions.club') -&gt;orwhere('tournament_match_plan.team_2', '=', 'push_subscriptions.club') -&gt;get(); dd($matchingSubscriptions); }</pre> <p>这是调试结果:</p> <pre class="brush:php;toolbar:false;">IlluminateSupportCollection {#751 ▼ // appHttpControllersGuestsGuestsPushController.php:97 #items: [] #escapeWhenCastingToString: false }</pre> <p>为什么我的 Laravel 代码没有结果?</p> <p>我在 PhpMyAdmin 中尝试了相同的查询:</p> <pre class="brush:php;toolbar:false;">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);</pre> <p>使用这个查询我得到了一个结果,并且是正确的。</p>
P粉111627787
P粉111627787

全部回复(1)
P粉198749929

以下是工作代码。

$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();
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号