<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之旅 廣告
                # 定義模型與其屬性 ### [](https://octobercms.com/docs/database/model#defining-models)定義模型 在大多數情況下,應該為每個數據庫表創建一個模型類。所有模型類都必須擴展`Model`該類。插件內部使用的模型的最基本表示如下: ~~~ namespace Acme\Blog\Models; use Model; class Post extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'acme_blog_posts'; } ~~~ 該`$table`保護字段指定相應的模型數據庫表。表名稱是作者,插件和復數記錄類型名稱的蛇形名稱。 ### [](https://octobercms.com/docs/database/model#standard-properties)支持的屬性 除了[模型特征](https://octobercms.com/docs/database/traits)提供的那些標準屬性外,還可以在模型上找到一些標準屬性。例如: ~~~ class User extends Model { protected $primaryKey = 'id'; public $exists = false; protected $dates = ['last_seen_at']; public $timestamps = true; protected $jsonable = ['permissions']; protected $guarded = ['*']; } ~~~ | 屬性 | 描述 | | --- | --- | | **$primaryKey** | 用于標識模型的主鍵名稱。 | | **$incrementing** | 布爾值,如果為false表示主鍵不是遞增的整數值。 | | **$exists** | 布爾值,如果為true表示模型存在。 | | **$dates** | 提取后,這些值將轉換為Carbon / DateTime對象的實例。 | | **$timestamps** | 布爾值,如果為true,將自動設置created\_at和Updated\_at字段。 | | **$jsonable** | 值在保存之前被編碼為JSON,并在獲取后轉換為數組。 | | **$fillable** | 值是可進行[批量分配的](https://octobercms.com/docs/database/model#mass-assignment)字段。 | | **$guarded** | 值是防止[質量分配的](https://octobercms.com/docs/database/model#mass-assignment)字段。 | | **$visible** | 值是[序列化模型數據](https://octobercms.com/docs/database/serialization)時顯示的字段。 | | **$hidden** | 值是[序列化模型數據](https://octobercms.com/docs/database/serialization)時隱藏的字段。 | | **$connection** | 包含默認情況下模型使用的[連接名稱的](https://octobercms.com/docs/database/basics#accessing-connections)字符串。 | #### [](https://octobercms.com/docs/database/model#property-primary-key)首要的關鍵 模型將假定每個表都有一個名為的主鍵列`id`。您可以定義一個`$primaryKey`屬性以覆蓋此約定。 ~~~ class Post extends Model { /** * The primary key for the model. * * @var string */ protected $primaryKey = 'id'; } ~~~ #### [](https://octobercms.com/docs/database/model#property-incrementing)增量式 模型將假定主鍵是一個遞增的整數值,這意味著默認情況下,主鍵將自動轉換為整數。如果您希望使用非增量或非數字主鍵,則必須將public`$incrementing`屬性設置為false。 ~~~ class Message extends Model { /** * The primary key for the model is not an integer. * * @var bool */ public $incrementing = false; } ~~~ #### [](https://octobercms.com/docs/database/model#property-timestamps)時間戳記 默認情況下,模型將期望`created_at`和`updated_at`列存在于你的表。如果您不希望自動管理這些列,請將`$timestamps`模型上的屬性設置為`false`: ~~~ class Post extends Model { /** * Indicates if the model should be timestamped. * * @var bool */ public $timestamps = false; } ~~~ 如果需要自定義時間戳的格式,請`$dateFormat`在模型上設置屬性。此屬性確定日期屬性在數據庫中的存儲方式,以及將模型序列化為數組或JSON時的格式: ~~~ class Post extends Model { /** * The storage format of the model's date columns. * * @var string */ protected $dateFormat = 'U'; } ~~~ #### [](https://octobercms.com/docs/database/model#property-jsonable)值存儲為JSON 將屬性名稱傳遞給`$jsonable`屬性后,值將作為JSON從數據庫中序列化和反序列化: ~~~ class Post extends Model { /** * @var array Attribute names to encode and decode using JSON. */ protected $jsonable = ['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>

                              哎呀哎呀视频在线观看