Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Blade Components Slots

Use slots for flexible component content injection.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Default Slot
  2. Named Slots
  3. Slot Attributes

Component slots:

Default Slot

blade
<!-- components/card.blade.php -->
<div class="card">
    {{ $slot }}
</div>

<!-- Usage -->
<x-card>
    Card content here
</x-card>

Named Slots

blade
<div class="card">
    <div class="header">{{ $header }}</div>
    <div class="body">{{ $slot }}</div>
    <div class="footer">{{ $footer }}</div>
</div>

<x-card>
    <x-slot:header>Title</x-slot>
    Body content
    <x-slot:footer>Footer</x-slot>
</x-card>

Slot Attributes

blade
<div {{ $header->attributes->class(['header']) }}>
    {{ $header }}
</div>
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read