• <legend id='6w8w0'><style id='6w8w0'><dir id='6w8w0'><q id='6w8w0'></q></dir></style></legend>

      <bdo id='6w8w0'></bdo><ul id='6w8w0'></ul>

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

        <small id='6w8w0'></small><noframes id='6w8w0'>

      3. Laravel eloquent 集合上的 Array_unique

        时间:2023-09-24
      4. <i id='oeGFl'><tr id='oeGFl'><dt id='oeGFl'><q id='oeGFl'><span id='oeGFl'><b id='oeGFl'><form id='oeGFl'><ins id='oeGFl'></ins><ul id='oeGFl'></ul><sub id='oeGFl'></sub></form><legend id='oeGFl'></legend><bdo id='oeGFl'><pre id='oeGFl'><center id='oeGFl'></center></pre></bdo></b><th id='oeGFl'></th></span></q></dt></tr></i><div id='oeGFl'><tfoot id='oeGFl'></tfoot><dl id='oeGFl'><fieldset id='oeGFl'></fieldset></dl></div>
        <tfoot id='oeGFl'></tfoot>

        <legend id='oeGFl'><style id='oeGFl'><dir id='oeGFl'><q id='oeGFl'></q></dir></style></legend>
        • <small id='oeGFl'></small><noframes id='oeGFl'>

            <bdo id='oeGFl'></bdo><ul id='oeGFl'></ul>
              <tbody id='oeGFl'></tbody>

                1. 本文介绍了Laravel eloquent 集合上的 Array_unique的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  不确定这是否可行,但我尝试在我拥有的一组项目上运行 array_unique,以删除重复项.虽然我无法让它工作.

                  Not sure if this is possible but im trying to run array_unique over a collection of items i have, to remove duplicates. Although i cannot get it working.

                  我的控制器逻辑:

                      // init models
                      $jobs = Job::search();
                      $countries = $jobs->get()->map(function( $job ) {
                  
                          return $job->country;
                      });
                      $countries = array_unique( $countries->toArray() );
                  

                  虽然这会得到数组到字符串的转换"错误

                  although this gets a "Array to string conversion" error

                  推荐答案

                  您可以使用 distinctgroup by 在您的选择子句中.但是,如果您真的需要在对象数组上具有唯一值,您可以执行以下操作:

                  You can have unique values in your DB results using distinct or group by in your select clause. But, if you really need to have unique values over an array of object you can do the following:

                  $uniques = array();
                  foreach ($countries as $c) {
                      $uniques[$c->code] = $c; // Get unique country by code.
                  }
                  
                  dd($uniques);
                  

                  这篇关于Laravel eloquent 集合上的 Array_unique的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Eloquent 将十进制转换为字符串 下一篇:Laravel Eloquent Pluck 不会丢失钥匙

                  相关文章

                  最新文章

                  <tfoot id='8JwFf'></tfoot>
                2. <legend id='8JwFf'><style id='8JwFf'><dir id='8JwFf'><q id='8JwFf'></q></dir></style></legend>

                  <small id='8JwFf'></small><noframes id='8JwFf'>

                    <bdo id='8JwFf'></bdo><ul id='8JwFf'></ul>

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