From a Laravel controller how to separate the business logic with data access logic?

-3

I am new to Laravel and I do not like that in a controller, business logic or data processing logic mixed with data access logic is made.

If we see the example of Codeigniter has the controllers and the models. Models have access to data and controllers call those functions.

I thought that Laravel could do something like this, like for example:

  • A controller that has access to data and another that calls those functions.
  • A driver that calls another file that has access to data.
  • I really do not know how to approach the problem because I'm new to Laravel and with the examples I'm suddenly violating Laravel's good practices.

        
    asked by Marck Vit 08.05.2018 в 21:56
    source

    1 answer

    1

    Laravel NO does business logic or interaction with persistent data from the controller, is the programmer who does it, is part of the best practices and SOLID.

    People who are new to Laravel have a hard time understanding that Laravel does not necessarily use a conventional MVC, that typical pattern is not implemented and can be read and deduced easily in their documentation. Taylor Otwell (the creator of Laravel) has spoken publicly on several occasions as well.

    In any case, I have worked with both frameworks and although Codeigniter seems to be a bit more rudimentary (it is easier for newbies), Laravel is simple and robust, its learning curve is very smooth, as long as have good programming bases and understand SOLID, OOP, design patterns.

    Regarding the specific problem, Laravel includes the models and their eloquent ORM, together they are a much more elaborate tool than those offered by Codeigniter. If you want to have a greater abstraction and strictly follow the SOLID principles (at the beginning of the question it seems to be what you would like to do), you can use repositories.

    As for what you propose:

      

    A controller that has access to data and another that calls those functions.

    It is a bad practice in any language or project that one controller calls another.

      

    A driver that calls another file that has access to data.

    If you refer to another file as the model or a repository or service, then yes, this is a better solution.

    In the end, keep in mind that Laravel is just a tool that limits practically nothing, the possibilities are the language, which is still PHP and the design patterns are the same as in any other project.

        
    answered by 09.05.2018 в 15:33