Support the ongoing development of Laravel.io →
Architecture
Last updated 2 years ago.
0

They're only loaded into memory when you actually call for them in your controller.

So, having lots of models doesn't have any performance impact.

Last updated 2 years ago.
0

Hi trololosha4real, you could use the Dependency Injection principle for inject the Model Dependencies into your Controller, but better than this, you could use the following roadmap:

1.- Define your Model > 2.- Define one Repository that use the Model defined > 3.- Inject the Repository in the Controller Constructor.

Then you don't need to know how the model works with the Database, and the Repository is a bridge between the Model and the Controller that allow you to disconnect the data layer from your controller, because of you could use a Database to get the data or another method to get it.

Later if you need you could use the IoC container to invert the dependency in a application central way.

Hope it helps you.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.