У меня есть оригинальный запрос, который я сделал в программе Navicat:
SELECT
tt1.team AS team1,
tt2.team AS team2,
tt1.logo AS team1_logo,
tt2.logo AS team2_logo,
tt1.id AS team1_id,
tt2.id AS `team2_id,`,
tournaments_matches.`status`,
tournaments_matches.started_at,
tt1.x AS x1,
tt2.x AS x2,
tournaments_matches.live,
tournaments_matches.winner_id
FROM
tournaments_teams AS tt1
INNER JOIN tournaments_teams AS tt2 ON tt1.match_id = tt2.match_id AND tt1.id != tt2.id
INNER JOIN tournaments_matches ON tournaments_matches.match_id = tt2.match_id AND tournaments_matches.match_id = tt1.match_id
GROUP BY
tt1.match_id
Я попытался переделать этот запрос в Laravel Query Builder, я получил это:
$opponents = DB::select('tt1.team as team1','tt2.team as team2','tt1.logo as team1_logo','tt2.logo as team2_logo','tt1.id as team1_id','tt2.id as team2_id,','tournaments_matches.status','tournaments_matches.started_at','tt1.x as x1','tt2.x as x2','tournaments_matches.live','tournaments_matches.winner_id')
->from('tournaments_teams as tt1')
->join('tournaments_teams as tt2', function($join) {
$join->on('tt1.match_id', '=', 'tt2.match_id')
->on('tt1.id', '!=', 'tt2.id');
})
->join('tournaments_matches', function($join) {
$join->on('tournaments_matches.match_id', '=', 'tt2.match_id')
->on('tournaments_matches.match_id', '=', 'tt1.match_id');
})
->groupBy('tt1.match_id')
->get();
var_dump($opponents); exit;
tournaments_teams
и tournaments_matches
это разные таблицы в базе данных.
Но когда я пытаюсь получить доступ к странице, var_dump
сообщает мне ошибку Type error: Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, string given, called in
. В чем проблема? Как я могу это исправить?