我有一个team_members
表,它具有以下结构,其中只有project_request_id
被更新。我创建了具有相同数据结构的log_team_members
,所以每当更新team_members时,我都会丢失旧数据(我需要读取这些数据),这就是为什么我想创建一个trigger
的{{1}},它将整个before updating team_members project_request_id
保存到此表中。
您能帮我从Latavel迁移中构建触发器吗?
old row
team_members更新发生的位置:
public function up()
{
Schema::create('team_members', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('title');
$table->string('picture');
$table->string('email')->unique();
$table->string('phone_number');
$table->text('background_information')->nullable();
$table->timestamps();
$table->integer('project_request_id')->unsigned();
$table->foreign('project_request_id')->references('id')->on('project_requests')->onDelete('cascade');
});
}
public function up()
{
Schema::create('team_members', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('title');
$table->string('picture');
$table->string('email')->unique();
$table->string('phone_number');
$table->text('background_information')->nullable();
$table->timestamps();
$table->integer('project_request_id')->unsigned();
$table->foreign('project_request_id')->references('id')->on('project_requests')->onDelete('cascade');
});
}
答案 0 :(得分:0)
// use DB;
$data = UpdateModelName::find(1);
$copy = $data->replicate()->toArray();
// store data in new table
$newTable = new NewTableModel;
$newTable->insert($copy);