Skip to content
Advertisement

php/codeigniter firestore update giving error InvalidArgumentException Input missing required one or more required keys

I am trying to connect admin panel on php-codeigniter with firestore/firebase . Insertion,Fetch and Set functions are working fine but when I try to update ( update a single key ) it gives InvalidArgumentException . I am following the official documentation here . I am new to firestore. Suggestions are appreciated.

Here’s my code

<?php
require 'vendor/autoload.php';
use KreaitFirebaseFactory;

class Panelmodel extends CI_Model
{

    public function __construct()
    {
        parent::__construct();
        $factory = (new Factory)->withServiceAccount(FCPATH . "/settings/firebase.json")
            ->createFirestore();
        $this->db = $factory->database();
    }


function update($id)
    {
        $document = $this->db->collection('Users')
            ->document($id);

        $document->update([['status' => false]]);
    }


}

Error Output

<h4>An uncaught Exception was encountered</h4>

<p>Type: InvalidArgumentException</p>
<p>Message: Input missing required one or more required keys. Required keys are path, value</p>
<p>Filename: /var/www/doer/vendor/google/cloud-core/src/ValidateTrait.php</p>

Advertisement

Answer

According to my understanding of provided documentation update syntax should be like this:

$document->update([
       ['path' => 'status' , 'value' => false]
]);

Here is API documentation. The syntax from the code should work with set (reference).

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