<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?[集合基類](https://laravel-china.org/docs/laravel/5.4/collections),因此它自然也繼承了許多可用于與 Eloquent 模型交互的方法。 當然,所有集合都可以作為迭代器,來讓你像遍歷一個 PHP 數組一樣來遍歷一個集合: ~~~ $users = App\User::where('active', 1)->get(); foreach ($users as $user) { echo $user->name; } ~~~ 然而,集合比數組更強大的地方是其使用了各種 map / reduce 的直觀操作。例如,我們移除所有未激活的用戶模型和收集其余各個用戶的名字: ~~~ $users = App\User::where('active', 1)->get(); $names = $users->reject(function ($user) { return $user->active === false; }) ->map(function ($user) { return $user->name; }); ~~~ > {note} 大部分的 Eloquent 集合會返回新的「Eloquent 集合」實例,但是?`pluck`,?`keys`,?`zip`,?`collapse`,?`flatten`?和?`flip`?方法會返回?[基礎集合](https://laravel-china.org/docs/laravel/5.4/collections)?實例。 > > 相應的,如果一個?`map`?操作返回一個不包含任何 Eloquent 模型的集合,那么它將會自動轉換成基礎集合。 ## 可用的方法 ### 集合對象 所有 Eloquent 集合都繼承了基礎的?[Laravel 集合](https://laravel-china.org/docs/laravel/5.4/collections)?對象。因此,他們也繼承了所有集合類提供的強大的方法: [all](https://laravel-china.org/docs/laravel/5.4/collections#method-all) [avg](https://laravel-china.org/docs/laravel/5.4/collections#method-avg) [chunk](https://laravel-china.org/docs/laravel/5.4/collections#method-chunk) [collapse](https://laravel-china.org/docs/laravel/5.4/collections#method-collapse) [combine](https://laravel-china.org/docs/laravel/5.4/collections#method-combine) [contains](https://laravel-china.org/docs/laravel/5.4/collections#method-contains) [count](https://laravel-china.org/docs/laravel/5.4/collections#method-count) [diff](https://laravel-china.org/docs/laravel/5.4/collections#method-diff) [diffKeys](https://laravel-china.org/docs/laravel/5.4/collections#method-diffkeys) [each](https://laravel-china.org/docs/laravel/5.4/collections#method-each) [every](https://laravel-china.org/docs/laravel/5.4/collections#method-every) [except](https://laravel-china.org/docs/laravel/5.4/collections#method-except) [filter](https://laravel-china.org/docs/laravel/5.4/collections#method-filter) [first](https://laravel-china.org/docs/laravel/5.4/collections#method-first) [flatMap](https://laravel-china.org/docs/laravel/5.4/collections#method-flatmap) [flatten](https://laravel-china.org/docs/laravel/5.4/collections#method-flatten) [flip](https://laravel-china.org/docs/laravel/5.4/collections#method-flip) [forget](https://laravel-china.org/docs/laravel/5.4/collections#method-forget) [forPage](https://laravel-china.org/docs/laravel/5.4/collections#method-forpage) [get](https://laravel-china.org/docs/laravel/5.4/collections#method-get) [groupBy](https://laravel-china.org/docs/laravel/5.4/collections#method-groupby) [has](https://laravel-china.org/docs/laravel/5.4/collections#method-has) [implode](https://laravel-china.org/docs/laravel/5.4/collections#method-implode) [intersect](https://laravel-china.org/docs/laravel/5.4/collections#method-intersect) [isEmpty](https://laravel-china.org/docs/laravel/5.4/collections#method-isempty) [keyBy](https://laravel-china.org/docs/laravel/5.4/collections#method-keyby) [keys](https://laravel-china.org/docs/laravel/5.4/collections#method-keys) [last](https://laravel-china.org/docs/laravel/5.4/collections#method-last) [map](https://laravel-china.org/docs/laravel/5.4/collections#method-map) [max](https://laravel-china.org/docs/laravel/5.4/collections#method-max) [merge](https://laravel-china.org/docs/laravel/5.4/collections#method-merge) [min](https://laravel-china.org/docs/laravel/5.4/collections#method-min) [only](https://laravel-china.org/docs/laravel/5.4/collections#method-only) [pluck](https://laravel-china.org/docs/laravel/5.4/collections#method-pluck) [pop](https://laravel-china.org/docs/laravel/5.4/collections#method-pop) [prepend](https://laravel-china.org/docs/laravel/5.4/collections#method-prepend) [pull](https://laravel-china.org/docs/laravel/5.4/collections#method-pull) [push](https://laravel-china.org/docs/laravel/5.4/collections#method-push) [put](https://laravel-china.org/docs/laravel/5.4/collections#method-put) [random](https://laravel-china.org/docs/laravel/5.4/collections#method-random) [reduce](https://laravel-china.org/docs/laravel/5.4/collections#method-reduce) [reject](https://laravel-china.org/docs/laravel/5.4/collections#method-reject) [reverse](https://laravel-china.org/docs/laravel/5.4/collections#method-reverse) [search](https://laravel-china.org/docs/laravel/5.4/collections#method-search) [shift](https://laravel-china.org/docs/laravel/5.4/collections#method-shift) [shuffle](https://laravel-china.org/docs/laravel/5.4/collections#method-shuffle) [slice](https://laravel-china.org/docs/laravel/5.4/collections#method-slice) [sort](https://laravel-china.org/docs/laravel/5.4/collections#method-sort) [sortBy](https://laravel-china.org/docs/laravel/5.4/collections#method-sortby) [sortByDesc](https://laravel-china.org/docs/laravel/5.4/collections#method-sortbydesc) [splice](https://laravel-china.org/docs/laravel/5.4/collections#method-splice) [sum](https://laravel-china.org/docs/laravel/5.4/collections#method-sum) [take](https://laravel-china.org/docs/laravel/5.4/collections#method-take) [toArray](https://laravel-china.org/docs/laravel/5.4/collections#method-toarray) [toJson](https://laravel-china.org/docs/laravel/5.4/collections#method-tojson) [transform](https://laravel-china.org/docs/laravel/5.4/collections#method-transform) [union](https://laravel-china.org/docs/laravel/5.4/collections#method-union) [unique](https://laravel-china.org/docs/laravel/5.4/collections#method-unique) [values](https://laravel-china.org/docs/laravel/5.4/collections#method-values) [where](https://laravel-china.org/docs/laravel/5.4/collections#method-where) [whereStrict](https://laravel-china.org/docs/laravel/5.4/collections#method-wherestrict) [whereIn](https://laravel-china.org/docs/laravel/5.4/collections#method-wherein) [whereInLoose](https://laravel-china.org/docs/laravel/5.4/collections#method-whereinloose) [zip](https://laravel-china.org/docs/laravel/5.4/collections#method-zip) ## 自定義集合 如果你需要使用一個自定義的?`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>

                              哎呀哎呀视频在线观看