Skip to content
Advertisement

How to delete element of an array on Firestore using Laravel

I’m trying to update an element inside of an array on Cloud Firestore. I know that Firestore still don’t have the ability to update a single item of an element of the array. Instead, we can delete the entire element and then add the entire updated element again.

I have managed to add entire element but I don’t know how to delete the old element.

In my case, I have a list of data in a table with a button of each row. The button is to update the status in the element of the array.

Here is my function

JavaScript

Here my firestore data looks like firestore That is the status that I want to update. So to update we need to update the entire array right? In this case, how to delete appliedIpt[0]?

UPDATED status For Priyashree Bhadra’s question

I have tried sending this code

JavaScript

I got an error of

JavaScript

And according to the documentation for PHP, it have required parameters which are path and value. So I updated the code to this and nothing happens after executing this code.

JavaScript

Here is my data looks like on Laravel laravel

I don’t know how arrayRemove works on PHP, I just want to remove this entire element? this index

Advertisement

Answer

I have solved my own problem. I just decoded my encoded data as element and push it to the array so that it will find the correct element in the database.

Also I found that the way I put my data into the Firestore mostly dynamic. So by using json_decode to decode the encoded json make my data as dynamic.

If there’s any possible way to do other than this solution, I welcome your suggestions.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement