← Back to Course

Working with Components and Slots

While layouts handle full-page structure, Blade components are built for smaller, reusable pieces of interface — things like a button, a card, or an alert box that appear in many places with slightly different content each time.

What Is a Blade Component?

A component pairs a small Blade view with an optional PHP class that can hold logic, accept data, and expose it cleanly to the view. Components can be as simple as a single Blade file or as structured as a dedicated class for complex behavior.

Passing Data with Props

Data is passed into a component the same way HTML attributes are written, and Laravel automatically makes those values available inside the component's view. This keeps component usage feeling natural and declarative.

Slots for Flexible Content

Not every piece of content fits neatly into a named attribute — sometimes a component needs to wrap arbitrary HTML passed in by whatever uses it. That's what slots are for, letting a component define a placeholder that any caller can fill freely.

ConceptPurpose
Component classHolds logic and data preparation for a reusable UI piece
Component viewDefines the actual HTML markup for the component
PropsNamed values passed into a component, similar to HTML attributes
Default slotThe main content placed between a component's opening and closing tags
Named slotsAdditional, labeled content areas inside a component

Why Components Matter

With views, layouts, and components in place, the natural next step is handling data coming from users — which starts with how Laravel processes form requests.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course