<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                * * * * * [TOC] ## 簡介 Eloquent 返回的所有多結果集都是?`Illuminate\Database\Eloquent\Collection`?對象的實例,包括通過?`get`?方法檢索或通過訪問關聯關系獲取到的結果。 Eloquent 的集合對象繼承了 Laravel 的?[集合基類](http://www.hmoore.net/tonyyu/laravel_5_6/786241),因此它自然也繼承了數十種能優雅地處理 Eloquent 模型底層數組的方法。 當然,所有的集合都可以作為迭代器,你可以像遍歷簡單的 PHP 數組一樣來遍歷它們: ~~~ $users = App\User::where('active', 1)->get(); foreach ($users as $user) { echo $user->name; } ~~~ 不過,集合比數組更加強大,它通過更直觀的接口暴露出可鏈式調用的 map/reduce 等操作。例如,讓我們移除所有未激活的用戶并收集剩余用戶的名字: ~~~ $users = App\User::all(); $names = $users->reject(function ($user) { return $user->active === false; }) ->map(function ($user) { return $user->name; }); ~~~ > {note} 大多數 Eloquent 集合方法會返回新的 Eloquent 集合實例, 但是?`pluck`,?`keys`,?`zip`,?`collapse`,?`flatten`?和?`flip`?方法除外,它們會返回一個?[集合基類](http://www.hmoore.net/tonyyu/laravel_5_6/786241)?實例。同樣,如果?`map`?操作返回的集合不包含任何 Eloquent 模型,那么它會被自動轉換成集合基類。 ## 可用方法 ### 集合基類 所有 Eloquent 都繼承了基礎的?[Laravel 集合](http://www.hmoore.net/tonyyu/laravel_5_6/786241)?對象。因此,它們也繼承了所有集合基類提供的強大的方法: [all](http://www.hmoore.net/tonyyu/laravel_5_6/786241#all_155) [average](http://www.hmoore.net/tonyyu/laravel_5_6/786241#average_165) [avg](http://www.hmoore.net/tonyyu/laravel_5_6/786241#avg_169) [chunk](http://www.hmoore.net/tonyyu/laravel_5_6/786241#chunk_183) [collapse](http://www.hmoore.net/tonyyu/laravel_5_6/786241#collapse_209) [combine](http://www.hmoore.net/tonyyu/laravel_5_6/786241#combine_223) [concat](http://www.hmoore.net/tonyyu/laravel_5_6/786241#concat_237) [contains](http://www.hmoore.net/tonyyu/laravel_5_6/786241#contains_251) [containsStrict](http://www.hmoore.net/tonyyu/laravel_5_6/786241#containsStrict_294) [count](http://www.hmoore.net/tonyyu/laravel_5_6/786241#count_298) [crossJoin](http://www.hmoore.net/tonyyu/laravel_5_6/786241#crossJoin_310) [dd](http://www.hmoore.net/tonyyu/laravel_5_6/786241#dd_350) [diff](http://www.hmoore.net/tonyyu/laravel_5_6/786241#diff_371) [diffAssoc](http://www.hmoore.net/tonyyu/laravel_5_6/786241#diffAssoc_385) [diffKeys](http://www.hmoore.net/tonyyu/laravel_5_6/786241#diffKeys_408) [dump](http://www.hmoore.net/tonyyu/laravel_5_6/786241#dump_433) [each](http://www.hmoore.net/tonyyu/laravel_5_6/786241#each_454) [eachSpread](http://www.hmoore.net/tonyyu/laravel_5_6/786241#eachSpread_474) [every](http://www.hmoore.net/tonyyu/laravel_5_6/786241#every_494) [except](http://www.hmoore.net/tonyyu/laravel_5_6/786241#except_506) [filter](http://www.hmoore.net/tonyyu/laravel_5_6/786241#filter_522) [first](http://www.hmoore.net/tonyyu/laravel_5_6/786241#first_550) [firstWhere](http://www.hmoore.net/tonyyu/laravel_5_6/786241#firstWhere_570) [flatMap](http://www.hmoore.net/tonyyu/laravel_5_6/786241#flatMap_595) [flatten](http://www.hmoore.net/tonyyu/laravel_5_6/786241#flatten_615) [flip](http://www.hmoore.net/tonyyu/laravel_5_6/786241#flip_655) [forget](http://www.hmoore.net/tonyyu/laravel_5_6/786241#forget_669) [forPage](http://www.hmoore.net/tonyyu/laravel_5_6/786241#forPage_685) [get](http://www.hmoore.net/tonyyu/laravel_5_6/786241#get_699) [groupBy](http://www.hmoore.net/tonyyu/laravel_5_6/786241#groupBy_731) [has](http://www.hmoore.net/tonyyu/laravel_5_6/786241#has_824) [implode](http://www.hmoore.net/tonyyu/laravel_5_6/786241#implode_836) [intersect](http://www.hmoore.net/tonyyu/laravel_5_6/786241#intersect_859) [intersectByKeys](http://www.hmoore.net/tonyyu/laravel_5_6/786241#intersectByKeys_873) [isEmpty](http://www.hmoore.net/tonyyu/laravel_5_6/786241#isEmpty_891) [isNotEmpty](http://www.hmoore.net/tonyyu/laravel_5_6/786241#isNotEmpty_901) [keyBy](http://www.hmoore.net/tonyyu/laravel_5_6/786241#keyBy_911) [keys](http://www.hmoore.net/tonyyu/laravel_5_6/786241#keys_950) [last](http://www.hmoore.net/tonyyu/laravel_5_6/786241#last_967) [macro](http://www.hmoore.net/tonyyu/laravel_5_6/786241#macro_987) [make](http://www.hmoore.net/tonyyu/laravel_5_6/786241#make_991) [map](http://www.hmoore.net/tonyyu/laravel_5_6/786241#map_995) [mapInto](http://www.hmoore.net/tonyyu/laravel_5_6/786241#mapInto_1013) [mapSpread](http://www.hmoore.net/tonyyu/laravel_5_6/786241#mapSpread_1041) [mapToGroups](http://www.hmoore.net/tonyyu/laravel_5_6/786241#mapToGroups_1059) [mapWithKeys](http://www.hmoore.net/tonyyu/laravel_5_6/786241#mapWithKeys_1097) [max](http://www.hmoore.net/tonyyu/laravel_5_6/786241#max_1129) [median](http://www.hmoore.net/tonyyu/laravel_5_6/786241#median_1143) [merge](http://www.hmoore.net/tonyyu/laravel_5_6/786241#merge_1157) [min](http://www.hmoore.net/tonyyu/laravel_5_6/786241#min_1183) [mode](http://www.hmoore.net/tonyyu/laravel_5_6/786241#mode_1197) [nth](http://www.hmoore.net/tonyyu/laravel_5_6/786241#nth_1211) [only](http://www.hmoore.net/tonyyu/laravel_5_6/786241#only_1231) [pad](http://www.hmoore.net/tonyyu/laravel_5_6/786241#pad_1247) [partition](http://www.hmoore.net/tonyyu/laravel_5_6/786241#partition_1269) [pipe](http://www.hmoore.net/tonyyu/laravel_5_6/786241#pipe_1281) [pluck](http://www.hmoore.net/tonyyu/laravel_5_6/786241#pluck_1295) [pop](http://www.hmoore.net/tonyyu/laravel_5_6/786241#pop_1339) [prepend](http://www.hmoore.net/tonyyu/laravel_5_6/786241#prepend_1355) [pull](http://www.hmoore.net/tonyyu/laravel_5_6/786241#pull_1381) [push](http://www.hmoore.net/tonyyu/laravel_5_6/786241#push_1397) [put](http://www.hmoore.net/tonyyu/laravel_5_6/786241#put_1411) [random](http://www.hmoore.net/tonyyu/laravel_5_6/786241#random_1425) [reduce](http://www.hmoore.net/tonyyu/laravel_5_6/786241#reduce_1447) [reject](http://www.hmoore.net/tonyyu/laravel_5_6/786241#reject_1471) [reverse](http://www.hmoore.net/tonyyu/laravel_5_6/786241#reverse_1489) [search](http://www.hmoore.net/tonyyu/laravel_5_6/786241#search_1511) [shift](http://www.hmoore.net/tonyyu/laravel_5_6/786241#shift_1541) [shuffle](http://www.hmoore.net/tonyyu/laravel_5_6/786241#shuffle_1557) [slice](http://www.hmoore.net/tonyyu/laravel_5_6/786241#slice_1571) [sort](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sort_1597) [sortBy](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sortBy_1615) [sortByDesc](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sortByDesc_1663) [sortKeys](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sortKeys_1667) [sortKeysDesc](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sortKeysDesc_1691) [splice](http://www.hmoore.net/tonyyu/laravel_5_6/786241#splice_1695) [split](http://www.hmoore.net/tonyyu/laravel_5_6/786241#split_1745) [sum](http://www.hmoore.net/tonyyu/laravel_5_6/786241#sum_1759) [take](http://www.hmoore.net/tonyyu/laravel_5_6/786241#take_1798) [tap](http://www.hmoore.net/tonyyu/laravel_5_6/786241#tap_1824) [times](http://www.hmoore.net/tonyyu/laravel_5_6/786241#times_1839) [toArray](http://www.hmoore.net/tonyyu/laravel_5_6/786241#toArray_1871) [toJson](http://www.hmoore.net/tonyyu/laravel_5_6/786241#toJson_1889) [transform](http://www.hmoore.net/tonyyu/laravel_5_6/786241#transform_1901) [union](http://www.hmoore.net/tonyyu/laravel_5_6/786241#union_1919) [unique](http://www.hmoore.net/tonyyu/laravel_5_6/786241#unique_1933) [uniqueStrict](http://www.hmoore.net/tonyyu/laravel_5_6/786241#uniqueStrict_1991) [unless](http://www.hmoore.net/tonyyu/laravel_5_6/786241#unless_1995) [unwrap](http://www.hmoore.net/tonyyu/laravel_5_6/786241#unwrap_2017) [values](http://www.hmoore.net/tonyyu/laravel_5_6/786241#values_2035) [when](http://www.hmoore.net/tonyyu/laravel_5_6/786241#when_2057) [where](http://www.hmoore.net/tonyyu/laravel_5_6/786241#where_2079) [whereStrict](http://www.hmoore.net/tonyyu/laravel_5_6/786241#whereStrict_2105) [whereIn](http://www.hmoore.net/tonyyu/laravel_5_6/786241#whereIn_2109) [whereInStrict](http://www.hmoore.net/tonyyu/laravel_5_6/786241#whereInStrict_2135) [whereNotIn](http://www.hmoore.net/tonyyu/laravel_5_6/786241#whereNotIn_2139) [whereNotInStrict](http://www.hmoore.net/tonyyu/laravel_5_6/786241#whereNotInStrict_2165) [wrap](http://www.hmoore.net/tonyyu/laravel_5_6/786241#wrap_2169) [zip](http://www.hmoore.net/tonyyu/laravel_5_6/786241#zip_2193) ## 自定義集合 如果你需要在自己的擴展方法中使用自定義的?`Collection`?對象,可以在你自己的模型中重寫?`newCollection`?方法: ~~~ <?php namespace App; use App\CustomCollection; use Illuminate\Database\Eloquent\Model; class User extends Model { /** * 創建一個新的 Eloquent 集合實例對象。 * * @param array $models * @return \Illuminate\Database\Eloquent\Collection */ public function newCollection(array $models = []) { return new CustomCollection($models); } } ~~~ 一旦你定義了?`newCollection`?方法,任何時候都可以在 Eloquent 返回的模型的?`Collection`?實例中獲得你的自定義集合實例。如果你想要在應用程序的每個模型中使用同一個自定義集合,則應該在所有的模型繼承的模型基類中重寫?`newCollection`?方法。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看