[英]Laravel not updating null values to foreign key column
I have a problem with laravel when I try to update the record and add it's foreign key to NULL
it didn't update at all.当我尝试更新记录并将它的外键添加到NULL
时,laravel 遇到了问题,它根本没有更新。
there is no error appears and i check the
Mass Assignment
to没有出现错误,我检查了Mass Assignment
Schema::create('time_slots', function (Blueprint $table) {
$table->id();
$table->enum('duration', ['30', '60']);
$table->double('price', 6, 2)->nullable();;
$table->enum('currency', ['usd', 'egp'])->nullable();
$table->dateTime('start_time');
$table->dateTime('end_time');
$table->enum('status', ['available', 'booked', 'finished'])->default('available');
$table->enum('type', ['video', 'text', 'phone', 'not-set'])->default('not-set');
$table->unsignedBigInteger('session_id');
$table->foreign('session_id')->references('id')->on('sessions')->onDelete('cascade');
$table->unsignedBigInteger('patient_id')->nullable();
$table->foreign('patient_id')->references('id')->on('patients')->onDelete('cascade');
$table->timestamps();
});
$timeslot->currency = null;
$timeslot->price = null;
$timeslot->patient_id = null;
$timeslot->status = 'available'; // that is the only culomn that update correctly
$timeslot->save();
Just replace currency definition like this只需像这样替换货币定义
$table->enum('currency', [null,'usd', 'egp'])->nullable();
or this或这个
$table->enum('currency', ['usd', 'egp', null])->nullable()->default(null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.