Php Laravel/Mysql:无法将字段设置为null

Php Laravel/Mysql:无法将字段设置为null,php,mysql,laravel,voyager,Php,Mysql,Laravel,Voyager,我正在从事一个laravel项目,并试图在mysql数据库中复制一条记录。 复制后,我想将字段值设置为null(约会状态)。 除了新记录的值(约会状态)与原始记录相同(即使我将其设置为null)外,其他一切都正常 $newAppointment = $appointment->replicate(); //push to get the id for the cloned record $newAppointment->push(); $newAppo

我正在从事一个laravel项目,并试图在mysql数据库中复制一条记录。 复制后,我想将字段值设置为null(约会状态)。 除了新记录的值(约会状态)与原始记录相同(即使我将其设置为null)外,其他一切都正常

    $newAppointment = $appointment->replicate();
    //push to get the id for the cloned record
    $newAppointment->push();
    $newAppointment->duplicated_from_id = $appointment->id;
    $newAppointment->appointment_status = null;
    $newAppointment->save();
    //updating the old appointment
    $appointment->duplicated_to_id = $newAppointment->id;
    $appointment->save();

请尝试以下方法,而不是整个代码块:

// replicate as the new record with some different fields
$newAppointment = $appointment->replicate()->fill([
    'duplicated_from_id' => $appointment->id,
    'appointment_status' => null,
])->save();

// update some fields of initial original record
$appointment->update([
    'duplicated_to_id' => $newAppointment->id,
]);
更多信息,请查看