<tfoot id='SQwT0'></tfoot>

    <legend id='SQwT0'><style id='SQwT0'><dir id='SQwT0'><q id='SQwT0'></q></dir></style></legend>

      • <bdo id='SQwT0'></bdo><ul id='SQwT0'></ul>

      <small id='SQwT0'></small><noframes id='SQwT0'>

      <i id='SQwT0'><tr id='SQwT0'><dt id='SQwT0'><q id='SQwT0'><span id='SQwT0'><b id='SQwT0'><form id='SQwT0'><ins id='SQwT0'></ins><ul id='SQwT0'></ul><sub id='SQwT0'></sub></form><legend id='SQwT0'></legend><bdo id='SQwT0'><pre id='SQwT0'><center id='SQwT0'></center></pre></bdo></b><th id='SQwT0'></th></span></q></dt></tr></i><div id='SQwT0'><tfoot id='SQwT0'></tfoot><dl id='SQwT0'><fieldset id='SQwT0'></fieldset></dl></div>
    1. 使用 Laravel 4.1 对 UNION 查询进行排序

      时间:2023-09-23
      • <tfoot id='9T6Kb'></tfoot>
        <i id='9T6Kb'><tr id='9T6Kb'><dt id='9T6Kb'><q id='9T6Kb'><span id='9T6Kb'><b id='9T6Kb'><form id='9T6Kb'><ins id='9T6Kb'></ins><ul id='9T6Kb'></ul><sub id='9T6Kb'></sub></form><legend id='9T6Kb'></legend><bdo id='9T6Kb'><pre id='9T6Kb'><center id='9T6Kb'></center></pre></bdo></b><th id='9T6Kb'></th></span></q></dt></tr></i><div id='9T6Kb'><tfoot id='9T6Kb'></tfoot><dl id='9T6Kb'><fieldset id='9T6Kb'></fieldset></dl></div>

        <legend id='9T6Kb'><style id='9T6Kb'><dir id='9T6Kb'><q id='9T6Kb'></q></dir></style></legend>
        • <bdo id='9T6Kb'></bdo><ul id='9T6Kb'></ul>

              <small id='9T6Kb'></small><noframes id='9T6Kb'>

                <tbody id='9T6Kb'></tbody>

                本文介绍了使用 Laravel 4.1 对 UNION 查询进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我认为 Laravel 4 和 Laravel 4.1 之间的 union 发生了一些变化.我有 2 个模型.

                I think there is something changed in the union between Laravel 4 and Laravel 4.1. I have 2 models.

                $photos = DB::table('photos')->select('id', 'name', 'created_at');
                $videos = DB::table('videos')->select('id', 'name', 'created_at');
                

                我想合并 2 个查询并使用 created_at 字段对 2 个查询进行排序.

                I want to union the 2 querys and order the 2 querys with the created_at field.

                $photos = $photos->orderBy('created_at', 'desc');
                $combined = $photos->union($videos);
                

                使用 Laravel 4 它给了我这个查询:

                With Laravel 4 it gives me this query:

                select `id`, `name`, `created_at` from `videos`
                union
                select `id`, `name`, `created_at` from `photos`
                order by `created_at` desc
                

                这工作正常,它将两个查询的结果排序在一起.在 Laravel 4.1 中,它给了我这个查询:

                This works ok, it sorts the results for both querys together. In Laravel 4.1 it gives me this query:

                (select `id`, `name`, `created_at` from `videos`)
                union
                (select `id`, `name`, `created_at` from `photos` order by `created_at` desc)
                

                这会产生一个视频列表,然后是一个有序的照片列表.我需要有一个列表,其中对组合查询进行了排序.我想让 Laravel 给我这个查询:

                This results in a list of videos and after that an ordered list of photos. I need to have a list where the to combined querys are sorted. I want Laravel to give me this query:

                (select `id`, `name`, `created_at` from `videos`)
                union
                (select `id`, `name`, `created_at` from `photos`)
                order by `created_at` desc
                

                如何在 Laravel 中实现此功能?

                How do get this working in Laravel?

                推荐答案

                似乎在这个 pull request 中修复了:https://github.com/laravel/framework/pull/3901

                It seems to be fixed in this pull request: https://github.com/laravel/framework/pull/3901

                这篇关于使用 Laravel 4.1 对 UNION 查询进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何正确捕获 PHP 异常 (Laravel 5.1) 下一篇:Laravel 模型函数“create"和“create"有什么区

                相关文章

                最新文章

                1. <small id='X6Y9k'></small><noframes id='X6Y9k'>

                  <i id='X6Y9k'><tr id='X6Y9k'><dt id='X6Y9k'><q id='X6Y9k'><span id='X6Y9k'><b id='X6Y9k'><form id='X6Y9k'><ins id='X6Y9k'></ins><ul id='X6Y9k'></ul><sub id='X6Y9k'></sub></form><legend id='X6Y9k'></legend><bdo id='X6Y9k'><pre id='X6Y9k'><center id='X6Y9k'></center></pre></bdo></b><th id='X6Y9k'></th></span></q></dt></tr></i><div id='X6Y9k'><tfoot id='X6Y9k'></tfoot><dl id='X6Y9k'><fieldset id='X6Y9k'></fieldset></dl></div>

                2. <legend id='X6Y9k'><style id='X6Y9k'><dir id='X6Y9k'><q id='X6Y9k'></q></dir></style></legend>

                  • <bdo id='X6Y9k'></bdo><ul id='X6Y9k'></ul>
                3. <tfoot id='X6Y9k'></tfoot>