r/laravel • • 18d ago

Building Maintainable PHP Applications: Patterns and Principles

https://codyssey.dev/courses/building-maintainable-php-applications-patterns-and-principles

Hey all,

I wrote a free course about a bunch of the most popular and most hated design patterns and principles with realistic examples in PHP (Laravel and Symfony).

There are a few of them that are missing but I’ll add them as a bonus at some point or maybe a separate course.

Let me know what you think.

Thanks.

60 Upvotes

6 comments sorted by

11

u/prateekshawebdesign 14d ago

One pattern that consistently keeps medium to large Laravel applications clean without over-engineering is adopting single-action classes combined with dedicated Form Requests. The classic repository pattern often ends up duplicating Eloquent's built-in query builder methods for zero practical benefit unless you are swapping persistence layers. Encapsulating complex business operations in single Invokable action classes keeps controllers to two lines of code, makes unit testing straightforward, and avoids bloated 2,000-line Eloquent models.

2

u/FishingDry768 13d ago

I agree. Actions can also call other actions. Making refactoring an action into smaller actions so much easier. For laravel, this is imo the best pattern. Combine them with spatie’s DTO’s for full typefety and it’s just perfect!

2

u/randomInterest92 12d ago

Yes 100% . All reasons for why repository pattern should be used are already satisfied by modern eloquent and the capabilities to extend it

0

u/davorminchorov 14d ago edited 13d ago

That works fine in some contexts but not in others. I covered all of that in the specific lessons for the service and repository pattern lessons.

The main downside is that actions usually get bloated with all of the code it will have from queries to validation to domain logic so it becomes harder to maintain.

2

u/kryptoneat 13d ago

Can you please disclose AI use for the writing of this course ?

2

u/davorminchorov 13d ago edited 13d ago

Yeah, I did use AI to help me write the course and structure it in a way where it is understandable, otherwise it would’ve taken me a while to write it. It’s based on the same ideas that I use in my personal projects.

The content is based on other resources, not just training data.

Let me know if you find any issues or if something is not understandable.