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.
There is no error and I check the Mass Assignment too.
Migration file:
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();
});
Update query
$timeslot->currency = null;
$timeslot->price = null;
$timeslot->patient_id = null;
$timeslot->status = 'available'; // that is the only column that update correctly
$timeslot->save();
Timeslotrecord also get persisted. I have setprotected $guarded = [];onTimeslotmodel. MySQL Ver 8.0.19, PHP 7.4.12. Are you getting any errors - maybe in log file(s)? Pls check