Category: Laravel

In this article I will explain why you should never use Eloquent models inside of your controllers. Next you will learn about Repository design pattern and how you can write database integration tests in Laravel application.

first of all, you are breaking SOLID principles: Also a couple of other principles like: In general by bloating your controllers, you make your system more difficult to maintain (because of all this copy-pasta), it is not flexible (you cannot just refactor to use another persisting driver) and spaghetti code (because you are mixing the layer references).

Also make sure to make it a standard in your company, this way you can harvest the benefits of re-usability.

In this video I will guide you on how to write a repository pattern and extract that nasty database logic from your controllers: And in this video I will explain you how to further enhance your infrastructure layer with Dependency Inversion Principle in order to de-couple a Controller from Database: This is just the beginning of how to write maintainable and scalable microservices in Laravel.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners