<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國際加速解決方案。 廣告
                Laravel 5.5 新增了向中間表模型插入或者更新數據時對類型轉換的支持。 目前,在原來的模型中你可以用 $casts 來雙向轉換。任何繼承 Eloquent\Model 類的模型都會查找 $casts 屬性,并在讀取和寫入時將指定的屬性轉化為數據類型。例如,[文檔](https://d.laravel-china.org/docs/5.4/eloquent-mutators#attribute-casting) 里面有個例子: ~~~ namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { /** * The attributes that should be cast to native types. * @var array */ protected $casts = [ 'is_admin' => 'boolean', ]; } ~~~ 在 Laravel 5.4 中,Taylor 也在自定義中間表模型上添加了定義 $casts 屬性的功能,但是只在讀取數據時應用了 $casts ,而插入或更新屬性時并不會執行轉換。 例如,假設你有 Runner 賽跑者模型和 Race 比賽模型。 一個跑步者可以有很多比賽,一場比賽可以有很多賽跑者。 我們把中間表模型稱為 RaceRunner,其中包括具有不同數量的單圈時間(取決于比賽的長度,以秒為單位)的 splits 數組,以及所需的 runner_id 和 race_id。 splits 數組在 race_runner 表中以 JSON 格式序列化,因此如果你在 RaceRunner 中間表模型的 $casts 中將 splits 定義為數組,那 dd 出來的結果就會是數組: ~~~ dd( $runner->pivot->splits ); // Example: [ 'Lap 1' => 150, 'Lap 2' => 163, 'Lap 3' => 146 ] ~~~ 只是,在創建或更新中間表模型時,你還是要手動轉換: ~~~ // Cast first... $splits = $splits->toJson(); // ...then attach: $runner->races()->attach($raceId, ['splits' => $splits]); ~~~ 現在,在 Laravel 5.5,Eloquent\Model 和 Eloquent\Relations\Pivot 類的 $casts 屬性都會 一模一樣。 無論你是讀取、插入還是更新數據,Laravel 都會「尊重」$casts 屬性的設置。 也就是 attach、sync 和 save 方法也可用于中間表模型。 這個新功能會應用在上面的例子里,即 // Cast first … 后面這一步的代碼將不再需要
                  <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>

                              哎呀哎呀视频在线观看