<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 模型操作 ### 介紹 October基于[Laravel的Eloquent](http://laravel.com/docs/eloquent)提供了一個漂亮而簡單的Active Record實現,用于處理您的數據庫。每個數據庫表都有一個對應的“模型”,用于與該表進行交互。使用模型可以查詢表中的數據,以及將新記錄插入表中。 模型類位于插件目錄的**models**子目錄中。模型目錄結構的示例: ~~~ plugins/ acme/ blog/ models/ user/ <=== Model config directory columns.yaml <=== Model config files fields.yaml <==^ User.php <=== Model class Plugin.php ~~~ 模型配置目錄可以包含模型的[列表列](https://octobercms.com/docs/backend/lists#list-columns)和[表單字段](https://octobercms.com/docs/backend/forms#form-fields)定義。模型配置目錄名稱與小寫形式的模型類名稱匹配。 ### [](https://octobercms.com/docs/database/model#extending-models)擴展模型 由于模型可以[使用行為](https://octobercms.com/docs/services/behaviors),因此可以使用靜態`extend`方法對其進行擴展。該方法采用閉包并將模型對象傳遞到其中。 在閉包內部,您可以向模型添加關系。在這里,我們擴展`Backend\Models\User`模型以包括引用該`Acme\Demo\Models\Profile`模型的配置文件(具有一個)關系。 ~~~ \Backend\Models\User::extend(function($model) { $model->hasOne['profile'] = ['Acme\Demo\Models\Profile', 'key' => 'user_id']; }); ~~~ 此方法還可以用于綁定到[本地事件](https://octobercms.com/docs/database/model#events),以下代碼偵聽該`model.beforeSave`事件。 ~~~ \Backend\Models\User::extend(function($model) { $model->bindEvent('model.beforeSave', function() use ($model) { // ... }); }); ~~~ > **注意:**通常,放置代碼的最佳位置是在插件注冊類`boot`方法中,因為它將在每個請求上運行,以確保對模型進行的擴展隨處可見。 此外,存在一些擴展受保護模型屬性的方法。 ~~~ \Backend\Models\User::extend(function($model) { // add cast attributes $model->addCasts([ 'some_extended_field' => 'int', ]); // add a date attribute $model->addDateAttribute('updated_at'); // add fillable or jsonable fields // these methods accept one or more strings, or an array of strings $model->addFillable('first_name'); $model->addJsonable('some_data'); }); ~~~
                  <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>

                              哎呀哎呀视频在线观看