久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel Eloquent Union 查詢

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
本文介紹了Laravel Eloquent Union 查詢的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

所以我有以下查詢:

$a = Model::where('code', '=', $code)
    ->where('col_a', '=' , 1)
    ->orderBy(DB::raw('FIELD(layout, "normal", "split", "flip", "double-faced", "") ASC, layout'))

$b = Model::where('code', '=', $code)
    ->where('col_b', '=' , 1)
    ->orderBy(DB::raw('FIELD(layout, "normal", "split", "flip", "double-faced", "") ASC, layout'))

$a->union($b)->get();

當(dāng)我先orderBy()"然后聯(lián)合時(shí),不會(huì)發(fā)生排序.

No sorting is happening when I 'orderBy()' first and then union.

當(dāng)我單獨(dú)查詢 '$a' 或 '$b' 時(shí),'orderBy()' 工作正常.

When I do query '$a' or '$b' individually the 'orderBy()' works fine.

當(dāng)我按照以下方式進(jìn)行時(shí),orderBy()"會(huì)作為一個(gè)整體發(fā)生.

When I do it in the following way 'orderBy()' happens as a whole.

$a->union($b)
    ->orderBy(DB::raw('FIELD(layout, "normal", "split", "flip", "double-faced", "") ASC, layout'))
    ->get();

我怎樣才能使orderBy()"分別適用于每個(gè)人,然后將結(jié)果合并回來?看起來它應(yīng)該可以工作.

How can I make it so the 'orderBy()' applies for each individually and then union the results back? It seems like it should work.

如果有人能提供一種方法來做到這一點(diǎn),即使它是普通的 MySQL,我也會(huì)選擇你的作為答案,因?yàn)槲艺J(rèn)為 Eloquent 可能存在錯(cuò)誤.

If anyone can provide a way to do this, even if it's normal MySQL, I will choose yours as the answer as I think there may be a bug with Eloquent.

推薦答案

嘗試以下操作:

$a = Model::where('code', '=', $code)
->where('col_a', '=' , 1);

$b = Model::where('code', '=', $code)->where('col_b', '=' , 1)
->union($a)
->get();

$result = $b;

這篇關(guān)于Laravel Eloquent Union 查詢的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

使用 json_encode對(duì)數(shù)組加密后,輸出的漢字部分是空的,怎么回事了? 各位大俠們,有沒有好的解決方案? 急救 解決辦法 你原始的數(shù)據(jù)是gbk的,這是不能被 json_encode 所接受的 json_encod
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實(shí)現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動(dòng)到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 中文字幕一区在线 | 99re在线视频| 成人中文字幕av | 国产精品欧美一区二区 | 国产精品久久久久一区二区三区 | 九色网址| 色综合一区二区三区 | 看黄在线 | 日本精品视频 | 国产一级片在线观看视频 | 免费午夜视频在线观看 | 亚洲免费人成在线视频观看 | 国产视频2021| 国产一区二区免费 | 国产一区二区精品自拍 | 日韩欧美国产不卡 | 亚洲精品在 | 亚洲一区国产 | 男女污污网站 | www.国产精 | 亚洲成av人片在线观看无码 | 九九九久久国产免费 | 91视频电影 | 日韩中文字幕在线播放 | av片免费观看 | 中文字幕在线三区 | 久久久久久成人 | 日韩色视频 | 黄色毛片在线看 | 国产在线精品一区二区三区 | 成人国内精品久久久久一区 | 成年免费大片黄在线观看岛国 | 99在线免费观看 | 国产精品亚洲综合 | 色婷婷一区二区三区四区 | 亚洲精品综合 | 呦呦在线视频 | 毛片一区二区三区 | 一区二区三区四区在线播放 | 水蜜桃久久夜色精品一区 | 91在线观看视频 |