Encapsulation: Hiding internal data and only exposing a clean public interface. The engine of a car is hidden — you only interact with the steering wheel and pedals. Encapsulation means hiding an object's internal details and only exposing what others need. You use a car through the steering wheel and pedals; the engine is under the bonnet.
In code, an Order class might keep its lines private and offer addLine() and total(). Other code cannot put the order in an invalid state, because every change goes through methods that check the rules.
What should you keep in mind with Encapsulation?
The benefit is freedom to change the inside without breaking the outside. You can switch how totals are calculated or stored, and code that calls total() keeps working. Keep properties private by default and expose behaviour rather than raw data. A class with public setters for everything has no real boundary, and its rules end up scattered across the codebase.
Apply Spatie's Laravel and PHP coding standards for any task that creates, edits, reviews, refactors, or formats Laravel/PHP code or Blade templates; use for controllers, Eloquent models, routes, config, validation, migrations, tests, and related files to align with Laravel conventions and PSR-12.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.