I think your suggestion of using a DataSource implementation is a good way to go. In fact, this can be a regular PHP implementation. I'd use a app/datasource namespace. There's no specific "Laravel way" of doing this. For the Profile you can use the Eloquent model as you already suggests.
Storing Objects Which Implement an Interface in the Database
Hi all,
I'm am currently trying to build a small web app which controls a MAX7219 LED matrix. The basic gist is I have a Python script which writes to the matrix, I want to be able to control the content from a web app, then all the Python script must do is hit an endpoint on the web app to retrieve the data to be displayed on the matrix. Primarily, the web app will retrieve it's data from an API, for example I might want to display local bus information, or what's currently playing on Spotify.
I'd like to make it as configurable as possible, so ideally in the web app, you can create a "profile" which is just a list of APIs to hit. Each of these APIs, naturally, will require some different configuration options too (weather information for example will require a city, and bus information will require a stop ID).
Truthfully, I don't have much experience with PHP so I'm looking a little help on how to architect this in Laravel (to date most of my experience is just simple web apps, URL shortening, image hosting etc.) - hopefully in a way that makes it quickly extensible to add new APIs (for example, just adding a new class which contains business logic for working with the API).
What would be the best way save this information to the database, I imagine having an interface, let's say DataSource which all my API classes implement (i.e. WeatherDataSource implements DataSource, SpotifyDataSource implements DataSource etc.) and an Eloquent model called Profile from which I can get an array of objects from which implement the DataSource interface, each of these classes will implement, let's say a getMessage() method which provides the string which should be displayed on the LED matrix, in the controller for the API it would be as simple as just building a JSON object by iterating through each of these objects and getting the message from said method.
I've looked at the service container but this seems (if I understand correctly) to allow resolution of an interface to a concrete class for the whole app, rather than on per object basis (the example in the docs is a Filesystem interface for which multiple types of filesystem may be used but this is consistent throughout the app). Some other examples I've found on StackOverflow seem to be the same thing.
Any help, even just links to docs that might be able to send me in the right direction would be amazing. Hopefully my explanation of what I'm trying to do is clear.
Please or to participate in this conversation.