XDfox
XDfox

Reputation: 53

"Unexpected 'StringLiteral'

enter image description here

I have no idea why has this error occurred.....Can Anyone help me? I try to make a connection to the firestore.

<br/>
<?php

require_once 'vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;

class GFireStore
{

    protected $db;
    protected $name;
    public function __construct(string $collection)
    {
        $this->db = new FirestoreClient([
            'projectId' -> 'final-fyp-project-1c86c'
        ]);
        
    
        $this->name = $collection;
    }


    public function getDocument(string $name){
        try{

            if($this->db.collection($this->name)->document($name)->snapshot()->exists()){

                return $this -> db.collection($this->name)->document($name)->snapshot()->data();
            }else{
                throw new Exception("Document are not exists");
            }
        }catch(Exception $exception){
            return $exception ->getMessage();
        }

    }


    

}

Upvotes: 0

Views: 153

Answers (1)

Grzegorz Pietrzak
Grzegorz Pietrzak

Reputation: 320

The proper syntax for PHP associative arrays is 'projectId' => 'final-fyp-project-1c86c'. The -> syntax is reserved for accessing object's properties and methods.

Upvotes: 1

Related Questions