midLaravel
What is dependency injection in Laravel?
Updated May 16, 2026
Short answer
Dependency injection provides class dependencies externally instead of creating them inside the class.
Deep explanation
Laravel automatically resolves dependencies using the service container. This improves testability and modularity.
Real-world example
Used in controllers to inject service classes.
Common mistakes
- Using 'new' keyword inside controllers.
Follow-up questions
- What is IoC container?
- Why DI improves testing?