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

200
Visualizações
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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If that is how you want to define your routes then you could have /db1/store or /db2/store be a route parameter

https://laravel.com/docs/8.x/routing#route-parameters

which would look like /{db}/store

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