mardi 25 mai 2021

Laravel project architecture for same model pointing at different tables

I created an application 3 years ago where it is possible to see the distribution of species and habitat in my country based on an official documentation. So I have the model "Species" and in the code of the model I have

protected $table = 'species';

and this happens for other 6 or 7 models (and the corresponding controllers).

Now, new official documentations came out and new data are available.

I can't overwrite those tables because the owner wants the possibility to check both the old data and the new ones.

So my question is: is there a way to structure the architecture of the models so that i can make the model pointing at a different table based on a "button" I click on the site or on a specific value I can set? Maybe something like this?

if ($some_value)
    protected $table = 'species';
else
    protected $table = 'species_new_data';


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34fWBF2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire