@lizeshakya I’m not sure what you mean by “design pattern” in your context. If you mean approach to Laravel projects, then I take a “DDD-lite” approach. I group models into directories based on the “part” of the application they’re in, and then create resource controllers around those models. Validation is put in form request classes and authorisation is handled by policies. Sticking to these conventions leads to slim controllers and easy-to-manage applications for me.
For me, it is being very difficult to implement SOLID design principle in Laravel application.
SOLID is just a way of approaching code. Laravel is very much open to using solid principles if you choose to.
How do you achieve SOLID principle in the existing project?
Well, that’s a difficult question to answer because it doesn’t have one, single answer. It depends on the project and what you’re trying to do with it. No one could possibly tell you how to implement SOLID in a project without knowing anything about the project itself or the current state of that project’s code.
My rough approach would be to whip models into shape. Models are the very core of your application; they are what your application is. If you have “bad” models, then all code you write from there is going to suffer. Define your models, and then go from there.
I’d then look at re-factoring any bad practices. Re-factor things to interfaces. Inject dependencies in classes. Bind things to the container. DRY out any code repeated in the codebase. Move logic from controllers to models. This steps should lead to a leaner, easier-to-manage codebase.