簡體   English   中英

Laravel 5用AND OR AND在雄辯的地方?

[英]Laravel 5 eloquent WHERE with AND OR AND?

我怎么能這樣說(a = 1和b> 1)或(c = 1和d> 1)?

這是我的代碼:

$playerMatches = Match::where(function ($query) use($id) {
                                $query->where('player_1_id', '=', $id)
                                    ->where('result_1', '>', 'result_2');
                                })
                            ->orWhere(function ($query) use($id) {
                                $query->where('player_2_id', '=', $id)
                                    ->where('result_2', '>', 'result_1');
                            })->get();

提前致謝!

$playerMatches = 
Match::where([['player_1_id', '=', $id],['result_1', '>', 'result_2']])
->orWhere([['player_2_id', '=', $id],['result_2', '>', 'result_1']])
->get();
if ( ! function_exists('sql_dump')) {
function sql_dump($connection = null)
{
    DB::connection($connection)->enableQueryLog();
    DB::listen(function ($sql) {
        $i = 0;
        $bindings = $sql->bindings;
        $rawSql = preg_replace_callback('/\?/', function ($matches) use ($bindings, &$i) {
            $item = isset($bindings[$i]) ? $bindings[$i] : $matches[0];
            $i++;
            if ($item instanceof DateTime) {
                $item = $item->format('Y-m-d H:i:s');
            }
            return gettype($item) == 'string' ? "'$item'" : $item;
        }, $sql->sql);
        echo $sql->time . '#' . $rawSql, "\n<br /><br />\n";
    });
}
}

在查詢之前調用sql_dump。 您將在響應中看到sql。

sql_dump();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM