intermediateLaravel
What is the difference between anonymous and class-based components?
Answer
Clear, interview-ready explanation
An anonymous component is a Blade view file with no associated PHP class. It is ideal for simple presentational components and can receive data through attributes, @props, the attribute bag, and slots.
A class-based component has a PHP class, usually in app/View/Components, plus a view or inline rendering logic. Its constructor and public methods or properties can prepare presentation data and support more involved behavior. Choose anonymous components for simple markup and class-based components when the component needs logic, dependencies, or a richer API.