簡體   English   中英

無法在Laravel / Eloquent中插入默認條目

[英]Cannot insert a default entry in Laravel/Eloquent

我有這個遷移:

public function up()
{
    Schema::create('player', function (Blueprint $table) {

        $table->increments('id');
        $table->integer('victories')->default(0);
        $table->timestamps();

    });

    for($i = 0 ; $i < 6 ; $i++){
        DB::table('player')->insert([]);
    }
}

我想插入5位玩家,但Eloquent不允許我加入。 它說插入函數需要一個參數。 此函數可以與其他我實際上需要在數組中輸入內容的遷移一起使用,但是如果為空,它將無法正常工作。

有什么幫助嗎?

嘗試:

for($i = 0 ; $i < 6 ; $i++) {
    DB::table('player')->insert(['id' => DB::raw('null')]);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM