How can I store a single data key in a JSON column cast as an array without deleting other keys?

I have a table called "Books" with a "notes" column.
Schema::create('books', static function (Blueprint $table): void {
// Other columns
$table->json('notes')->nullable();
});
Schema::create('books', static function (Blueprint $table): void {
// Other columns
$table->json('notes')->nullable();
});
The "notes" column is cast as an array.
protected $casts = [
'notes' => 'array',
];
protected $casts = [
'notes' => 'array',
];
The data that is being stored, looks something like this:
{
"brief_synopsis": "*sample text*",
"international": "*sample text*",
"long_summary": "*sample text*",
"formatting_notes": "*sample text*"
}
{
"brief_synopsis": "*sample text*",
"international": "*sample text*",
"long_summary": "*sample text*",
"formatting_notes": "*sample text*"
}
The problem that I am having is that when I create an Edit action that edits only one element, all of the others are set to null because a new array with a single key (the current one) is overwriting the entire field. I tried books->brief_synopsis, but that does not work either.
EditAction::make('Edit')
->label('Edit the brief synopsis)
->form([
RichEditor::make('books.brief_synopsis'),
])
->modal();
EditAction::make('Edit')
->label('Edit the brief synopsis)
->form([
RichEditor::make('books.brief_synopsis'),
])
->modal();
How can I set up my Edit action to update the target element without erasing the other elements?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server