Laravel Blade Templates: Components & Slots

<!-- /resources/views/alert.blade.php -->

<div class="alert alert-danger">
    {{ $slot }}
</div>
@component('alert')
    <strong>Whoops!</strong> Something went wrong!
@endcomponent
<!-- /resources/views/alert.blade.php -->

<div class="alert alert-danger">
    <div class="alert-title">{{ $title }}</div>

    {{ $slot }}
</div>
@component('alert')
    @slot('title')
        Forbidden
    @endslot

    You are not allowed to access this resource!
@endcomponent

Provide similar benefits to sections and layouts.

Passing Additional Data To Components

@component('alert', ['foo' => 'bar'])
    ...
@endcomponent

Aliasing Components

Use Illuminate\Support\Facades\Blade;

Blade::component('components.alert', 'alert');
@alert(['type' => 'danger'])
    You are not allowed to access this resource!
@endalert
@alert
    You are not allowed to access this resource!
@endalert

Laravel Blade Templates: Components & Slots — Structure map

Clickable & Draggable!

Laravel Blade Templates: Components & Slots — Related pages: