Laravel not updating null values to foreign key column

  laravel, mysql, php

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 appears and i check the Mass Assignment to

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 culomn that update correctly
 $timeslot->save();

Source: Laravel

Leave a Reply