简体   繁体   English

创建迁移 Laravel 后如何更新特定的列表值?

[英]How to update specific column table value after create migrations Laravel?

currently I want to update my existing table by adding new column.目前我想通过添加新列来更新我现有的表。 Let's say the column name is is_active with default value is true.假设列名为is_active ,默认值为 true。 I create new migrations for this.我为此创建了新的迁移。

Then I want to update specific item within this table so the is_active column is changed to false.然后我想更新此表中的特定项目,以便将is_active列更改为 false。 How to do this without doing this directly to the database so my teammate can also get this changes?如何在不直接对数据库执行此操作的情况下执行此操作,以便我的队友也可以获得此更改?

Should I create new seeder and call it within my migration?我应该创建新的播种机并在我的迁移中调用它吗?

您必须进行查询以更新特定列的is_active ,如下所示:

Model::where('id', $id)->update(['is_active' => 'false']);

Use migrations to add a column to your table:使用迁移向表中添加列:

Schema::table('your_table', function (Blueprint $table) {
    $table->boolean('is_active');
});

Then you can update the values of the selected items on your Model:然后您可以更新模型上所选项目的值:

YourModel::where('id', $id)
    ->update(['is_active' => 'false']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM