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

Laravel Eloquent Union 查詢

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
本文介紹了Laravel Eloquent Union 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(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)合時,不會發(fā)生排序.

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

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

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

當(dāng)我按照以下方式進(jìn)行時,orderBy()"會作為一個整體發(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()"分別適用于每個人,然后將結(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.

如果有人能提供一種方法來做到這一點,即使它是普通的 MySQL,我也會選擇你的作為答案,因為我認(rèn)為 Eloquent 可能存在錯誤.

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 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

使用 json_encode對數(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)容必須是實現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動到 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())
主站蜘蛛池模板: 夜久久| 9久久婷婷国产综合精品性色 | 日韩福利 | 亚洲欧美在线视频 | 91精品国产手机 | 中文字幕二区三区 | 精品一区二区三区免费毛片 | 91成人影院| 亚洲精品99 | 成人免费视频网站在线观看 | 国产精品久久久久久久久久免费看 | 国内毛片毛片毛片毛片 | 羞羞视频在线观免费观看 | 日韩精品无码一区二区三区 | 红桃成人在线 | 欧美黑人国产人伦爽爽爽 | 日本成人片在线观看 | 黄色大片免费网站 | 欧美高清视频一区 | 色精品视频 | 自拍偷拍第一页 | 日韩精品人成在线播放 | 91精品久久久久久久久久小网站 | 欧洲免费毛片 | 精品视频在线播放 | 欧美成人a | 亚洲精品黄色 | 91精品国产91久久久 | 一级欧美| 欧美视频1区| 一本一道久久a久久精品综合 | 国产一二三区精品视频 | 中文字幕在线一区二区三区 | 久久最新| 欧美成人免费在线视频 | 亚洲欧美日韩在线不卡 | 成人福利电影 | 91精品国产91久久久久久密臀 | 亚洲国产精品99久久久久久久久 | 殴美一级片| 国产成人久久精品一区二区三区 |