Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

418
Visualizações
offline/online data sync in firestore - Laravel

I am trying to develop a web app using Laravel and vue.js where I can sync data from firestore even if I am offline. I have seen in the features of firestore that it provides this feature. But I dont know how to this feature into my project. I have cloned suhasrkms/laravel-with-firestore for Firestore in Laravel. But main problem i am facing is i dont know how to add offline code/persistence. I tried to add the code in resources/js/offline-persistence.js which is provided in firestore doc. I have tried to add code as well in my blade file.
Kindly provide me the solution, your reply will be valuable for me.

<script type="text/javascript">


    firebase.firestore().enablePersistence()
        .catch((err) => alert(Something failed for enablePersistence, code: ${err.code}));

    firebase.firestore().collection('test')
        .onSnapshot(snaps => {
            if (snaps.empty) { return; }
            const preDataElm = document.getElementById("preData");
            while (preDataElm.firstChild) {
                preDataElm.removeChild(preDataElm.firstChild);
            }
            let list = snaps.docs.map(snap => {
                return {id: snap.id, ...snap.data()};
            });
            let newElm = document.createElement("PRE");
            newElm.innerText = JSON.stringify(list, null, 2);

            return preDataElm.appendChild(newElm);
        });

    function tryMe() {
        document.getElementById("result").innerHtml = "";
        firebase.firestore()
            .collection('test')
            .add({test: new Date().toString()})
            .then((docRef) => alert(Data inserted successfuly ID: ${docRef.id}));
    }
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To add offline code/persistence , you need to enable or disable offline persistence while initializing Cloud Firestore, as stated in the documentation:

  • For Android and iOS, offline persistence is enabled by default. To disable persistence, set the PersistenceEnabled option to false.

  • For the web, offline persistence is disabled by default.To enable persistence, call the enablePersistence method. Cloud Firestore's cache isn't automatically cleared between sessions.Consequently, if your web app handles sensitive information, make sure to ask the user if they're on a trusted device before enabling persistence.

You can also refer to the stackoverflow case1 and case2 where a similar issue has been faced by the OP which got resolved by setting up the persistence as:

FirebaseDatabase.getInstance().setPersistenceEnabled(true);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda