Laravel查詢失敗,但相同的程式碼在PhpMyadmin中有效
P粉111627787
P粉111627787 2023-08-15 17:54:08
0
1
430
<p>這是我 Laravel 應用程式的程式碼:</p> <pre class="brush:php;toolbar:false;">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); }</pre> <p>這是調試結果:</p> <pre class="brush:php;toolbar:false;">IlluminateSupportCollection {#751 ▼ // appHttpControllersGuestsGuestsPushController.php:97 #it​​ems: [] #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();
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!