lundi 7 mars 2022

Passing a route parameter / form data through all controller functions

Got a small problem I need help solving out, I'm using laravel version 8.

So I have 3 different databases which have the same tables, I made a model for each database.

So for reference:

  • Model DB1entries - DB1 - entries_table
  • Model DB2entries - DB2 - entries_table
  • Model DB3entries - DB3 - entries_table

So when sending a request i want all requests get to the same controller but the database can be changed depending on the request DB selected, can be with a param on the route.

for example:

  • /db1/store would go to EntriesController and create the entry in DB1

  • /db2/store would go to EntriesController and create the entry in DB2

but the "set" for the model wouldn't be the store function in EntriesController.

I just don't want to use the same function to set the model for each function inside the controller, I want to create it dynamically in the constructor or any other solution.

Aucun commentaire:

Enregistrer un commentaire