How to save empty string in database using laravel?

Member

by ryleigh , in category: PHP Frameworks , 10 months ago

How to save empty string in database using laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 10 months ago

@ryleigh 

To save an empty string in the database using Laravel, you can do the following:

  1. Define the column in your migration file as nullable:
1
$table->string('column_name')->nullable();


  1. In your controller, when saving the data, you can set the value to an empty string:
1
2
3
$model = new Model();
$model->column_name = '';
$model->save();


By setting the column as nullable in the migration file, you allow the column to accept NULL values. So when you set an empty string value, Laravel will save it as NULL in the database.

Related Threads:

How to save empty string in database using laravel?
How to save multiple table rows in database using laravel?
How to save base64 string as image in laravel?
How to save debug json to database in laravel?
How to connect database using ssl in laravel?
How to save image to another server using laravel?