Set laravel migration default value equal current database record or null

53 Views Asked by At

This is a migration for Blog database of a website that I'm developing for my own resume as portfolio:

public function up(): void
{
   Schema::create('blogs', function (Blueprint $table) {
      $table->id();
      $table->text('title');
      $table->text('image');
      $table->text('content');
      $table->text('category');
      $table->text('keywords');
      $table->text('author');
      $table->timestamps();
   });
}

I'm using filament to edit and update a record.

At edit form I don't want to upload new image (I don't want to change image) . While I submit form a null record posting to image column in database to set it null. But I don't want to even change or update image at all.

Is there anyway to set migration default value (on update) based on current database record?

Something like:

   $table->text('image')
      ->default(
         ($table->currentRecord->image !== null) ? $table->currentRecord->image : null
       );
0

There are 0 best solutions below