Laravel: Offline Mode?
Asked Answered
B

1

11

I want to make my web app (which is built with laravel) work offline...but I cant found out how to do it!

I am using the "app cache" for static files, but im not sure exactly how to handle the dynamic side of the app.

The app uses a database which im guessing I need to use localStorage for? (from what ive read online so far)

Im basically just looking for someone to point me in the right direction as im struggling to find much online on setting up Laravel for use offline

Thanks, Dave

Boaz answered 8/1, 2015 at 18:9 Comment(5)
You can’t. Laravel’s written in PHP, which is a server-side language. No server, no app. If you want your app to work offline, you need to look into a client-side language, like JavaScript.Rutger
what do you mean 'offline'? without Internet access? Just install all on localhost server for example XAMP - and you don't have to be plugged in :)Roos
I think you need to clarify your question, David. Do you mean you want to develop a Laravel app locally, or do you want your app to work offline for users on their devices?Rutger
A valid question @Boaz (+1) how did you implement the solution. What is actual feedback of client after using it in production...? I have to build such system and need to know if solution work in real life...Privilege
Hey @hhsadiq, we decided to use Meteor - which is awesome! using the Appcache Package (which stores the assets in the appcache) and the ground:db Package (which stores the db in local storage) we were able to use our app offline. We are currently using it to build an iOS and Android app using the Cordova Phonegap integration.Boaz
S
8

You can only have a static site offline with appcache. You cannot do this with laravel.

If you want to move the data into localstorage and have a semi- dynamic website, you have to completly change your architecture. Let me outline a possible approach :

A single page web app written in javascript ( using a framework like for instance ExtJs ) that connects to a backend in a form of a webservice that gives access to the database ( you could write it using laravel ).

When you are connected to the server you can load the data in localstorage When you are offline you can continue to work with the data. When the client reconnects, you have to synchronize the changes with the server.

Edit: As of 2020, Application Storage is deprecated. Look into ServiceWorkers instead.

Slantwise answered 8/1, 2015 at 18:28 Comment(6)
Thanks @Lorez Meyer! Will look into this! Thanks for giving me a solution rather than just telling me "you cant" and marking me down... much appreciated! :)Boaz
@LorenzMeyer i know this is an old question, but what about if u r using ajax with laravel, so on each request to the server u make "in case of updating or adding new record" we will check if the connection is down and if it is we will then use the html5 localStorage and notify the user that this data will be posted to the server once the connection is back, couldnt this be done ?Concelebrate
@Concelebrate I think what you propose can work. Even though I fear that the implementation will be heavy.Slantwise
@LorenzMeyer can u elaporate more plz, for the offline checking i was going to use something like krawczyk.io/heyoffline.jsConcelebrate
Really, I can't give advice on this. My answer already reflects what I can say to this question. I do not know much about Laravel. By the way, I think that the backend is not relevant.Slantwise
What framework do you use for the frontend? Ask another question aimed at what you are using.Slantwise

© 2022 - 2024 — McMap. All rights reserved.