久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      laravel5.4中軟刪除是什么

      在“Laravel5.4”中,軟刪除指的是將表記錄的狀態(tài)標(biāo)記上刪除狀態(tài),并不是真正的從數(shù)據(jù)庫(kù)中刪除了,這樣在查詢(xún)的時(shí)候就可以添加過(guò)濾;軟刪除能夠在表中以“deleted_at”字段值進(jìn)行標(biāo)識(shí),默認(rèn)值為null。

      laravel5.4中軟刪除是什么

      本文操作環(huán)境:Windows10系統(tǒng)、Laravel5.4版、Dell G3電腦。

      laravel5.4中軟刪除是什么

      軟刪除并不是真的從數(shù)據(jù)庫(kù)中刪除掉了, 而是在表中以deleted_at(這個(gè)字段的名稱(chēng)也是固定的)這個(gè)字段值標(biāo)識(shí)的, 需要在設(shè)計(jì)表的時(shí)候呢添加這個(gè)字段 deleted_at, 默認(rèn)值為null,

      所謂軟刪除指的是數(shù)據(jù)表記錄并未真的從數(shù)據(jù)庫(kù)刪除,而是將表記錄的標(biāo)識(shí)狀態(tài)標(biāo)記為軟刪除,這樣在查詢(xún)的時(shí)候就可以加以過(guò)濾,讓對(duì)應(yīng)表記錄看上去是被”刪除“了。Laravel中使用了一個(gè)日期字段作為標(biāo)識(shí)狀態(tài),這個(gè)日期字段可以自定義,這里我們使用deleted_at,如果對(duì)應(yīng)模型被軟刪除,則deleted_at字段的值為刪除時(shí)間,否則該值為空。

      軟刪除就是邏輯刪除,數(shù)據(jù)保留單標(biāo)記上刪除狀態(tài),一般我們會(huì)用刪除時(shí)間來(lái)作為標(biāo)記,這樣標(biāo)記狀態(tài)有了,刪除時(shí)間也有了。

      類(lèi)型為 timestamp('deleted_at')

      在模型中添加 use SoftDeletes

      use IlluminateDatabaseEloquentSoftDeletes;   class TestModel extends Model  {     use SoftDeletes;            protected $dates = ['deleted_at']; }

      示例如下:

      用Laravel 自帶的 Eloquent ORM 來(lái)實(shí)現(xiàn)軟刪除。

      首先在數(shù)據(jù)遷移文件中添加刪除時(shí)間字段

      ./database/migrations/2014_10_12_000000_create_users_table.php
      <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; return new class extends Migration {     /**      * Run the migrations.      *      * @return void      */     public function up()     {         Schema::create('users', function (Blueprint $table) {             $table->id();             $table->string('name');             $table->string('email')->unique();             $table->timestamp('email_verified_at')->nullable();             $table->string('password');             $table->rememberToken();             $table->timestamps();             $table->softDeletes()->comment('刪除時(shí)間');// 默認(rèn)添加 deleted_at 字段         });     }     /**      * Reverse the migrations.      *      * @return void      */     public function down()     {         Schema::dropIfExists('users');     } };

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)