ποΈ DDD in Laravel = everything has a home.
What you get:
β
Business logic in Domain layer
β
Orchestration in Use Cases
β
Framework code isolated
β
New devs onboard faster
$order->cancel() > $order->status = 'cancelled'
Structure brings clarity π―
#PHP
Posts by Renato Hysa
π₯ Unpopular: Model factories are overused.
Most tests need:
β User::factory()->create()
β
User::create(['email' => 'test@test.com'])
Save factories for:
* Database seeding
* Complex relationships
* Random data generation
Be explicit. Be clear π
#Laravel
π₯ Controversial: Static methods are fine, actually.
Good static use:
β
Math::round()
β
Str::slug()
β
Carbon::parse()
β
Validator::make()
Bad static use:
β DB::query()
β Cache::get()
Context matters. Stop the dogma π―
#PHP
β οΈ Singleton = anti-pattern alert.
Problems:
β Cannot mock for tests
β Global state
β Hidden dependencies
β Hard to maintainUse Dependency Injection instead β
#PHP
π Simple Factory = clean object creation.
Perfect for:
β
Dynamic object instantiation
β
Mockable for testing
β
Type-based creation
β
Centralized logic
One factory, many objects π
#PHP
π Prototype = clone instead of create.
Perfect for:
β
Mass data operations
β
Expensive object creation
β
Bulk record generation
β
Pre-configured templatesClone it, don't build it π
#PHP
β»οΈ Object Pool = stop wasting time creating objects.
Perfect for:
β
Database connections
β
HTTP clients
β
Expensive resources
β
High-frequency operations
Reuse, don't recreate π
#PHP
π Factory Method = dependency inversion done right.
Perfect for:
β
Multiple logger destinations
β
Testable with mock factories
β
Database/file/cloud storage
β
Zero client code changes
SOLID principles in action πͺ
#PHP
π¨ Builder Pattern = no more constructor chaos.Perfect for:
β
Complex object assembly
β
Multiple object variations
β
Step-by-step construction
β
Avoiding parameter overloadClean, flexible, maintainable πͺ
#PHP
I have used that in the next post, good catch ;)
π Abstract Factory = object creation made elegant.
Perfect for:
β
Multi-platform apps (Windows/Unix/Mac)
β
Swappable export formats (CSV/JSON/XML)
β
Theme systems (Dark/Light)
β
Test mocking without refactoring
One interface, unlimited implementations π
#PHP
Nested if-statements killing you?
Perfect for:
β
Less cognitive load
β
Obvious happy path
β
Fail fast, win clear
β
Reads like a checklist
Guard clauses > pyramids of doom π‘οΈ
#laravel
Still writing PHP like it's 2015?
Perfect for:
β
Less constructor boilerplate
β
Clean match expressions
β
Arrow function callbacks
β
Self-documenting calls
Modern PHP is clean π
#laravel
Breaking chains for side effects?
Perfect for:
β
Keep fluent chains flowing
β
Debug mid-chain easily
β
Side effects, no breaks
β
Natural top-to-bottom code
The chain never breaks π
#laravel
Processing huge datasets wrong?
Perfect for:
β
Handle millions of records
β
Right tool for the job
β
Safe updates while iterating
β
Chain methods on big data
Memory matters π§
#laravel
Windows users don't know what this screenshot is π
#ai
Interesting, what issues have you had and reached to support? Filament is open source, thus the community is the only support you can get π
Laravel devs
Why would someone prefer Laravel Nova over Filament PHP? Especially when you consider that Laravel Nova is a paid option. π€
#laravel
Searching multiple columns with orWhere?
Perfect for:
β
Apply constraint to many columns
β
No repetitive chains
β
Clean content filtering
β
Matches your intent
One method beats ten π―
#laravel
It's not about the setup, it's about what you get afterwards, if you use the address VO only once, then it doesn't make sense, but if it is crucial in your domain, why not create 1-2 extra classes?
This is a great refactoring example!
Query builder if-statements everywhere?
Perfect for:
β
Conditional clauses, no chain breaks
β
Clean search filter handling
β
No nested if-blocks
β
Default behavior with else
Keep the chain flowing π
#laravel
The before/after diff made my team actually say "wow." π small secrets really.
Collection closures too verbose?
Perfect for:
β
Call methods without closures
β
Cleaner transformation chains
β
Less boilerplate code
β
Readable nested access
One line beats five π
#laravel
Queue jobs killing your API limits?
Perfect for:
β
Respect API rate limits
β
Prevent service overload
β
Per-user throttling
β
No more 429 errors
Background work, under control ποΈ
#laravel
The examples are coming directly from the docs, I love value objects and that one is a good approach βΊοΈ
Manual JSON encode/decode everywhere?
Perfect for:
β
Rich value objects
β
Auto encrypt/decrypt
β
No manual transformation
β
Encapsulated domain logic
Work with objects, store as JSON π
#laravel
Moved all our user event handling to an observer and deleted 300 lines from the User model, code reviews take half the time now.
Model event logic scattered everywhere?
Perfect for:
β
Centralized event handling
β
Clean, focused models
β
Auto-sync across systems
β
Isolated testing
One observer beats 50 callbacks π―
#laravel
Your API needs rate limiting
Perfect for:
β
Protecting against abuse
β
Tiered access (free vs paid)
β
Custom limit segmentation
β
Fair resource allocation
Stop bleeding infrastructure costs πΈ
#laravel