且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Laravel 5迁移中更新表并添加数据

更新时间:2023-12-01 10:14:22

基于此链接,我找到了答案: https://***.com/a/23506744/4650792

Based on this link i found the answer: https://***.com/a/23506744/4650792

Schema::table('warrant_grants',function ($table){
        $table->string('name',100)->after('id')->nullable();
    });

    $results = DB::table('warrant_grants')->select('id','name')->get();

    $i = 1;
    foreach ($results as $result){
        DB::table('warrant_grants')
            ->where('id',$result->id)
            ->update([
                "name" => "Warrant-".$i
        ]);
        $i++;
    }

无论如何,谢谢大家的帮助.

Thanks for the help anyway guys.