Blade components are reusable pieces of UI — alerts, buttons, cards, form inputs — used like HTML tags: <x-alert>.
Anonymous components
Create a file in resources/views/components. The file components/alert.blade.php becomes <x-alert>. A file in a subfolder, components/form/input.blade.php, becomes <x-form.input>.
Props
Declare the attributes your component accepts with @props(['type' => 'info']). Pass them like HTML attributes: <x-alert type="success">. Use : to pass PHP values: :post="$post".
Slots
Whatever you put between the opening and closing tags arrives as {{ $slot }}. Named slots let you fill several areas: <x-slot:title>...</x-slot>.
Extra attributes
{{ $attributes->merge(['class' => 'alert']) }} adds any extra class or id the caller passes.
Class-based components
php artisan make:component Alert creates a PHP class plus a view, useful when the component needs logic (for example, loading data).
Components are also a modern alternative to @extends layouts: <x-layout> ... </x-layout>.
Example
{{-- resources/views/components/alert.blade.php --}}
@props(['type' => 'info'])
<div {{ $attributes->merge(['class' => 'alert alert-' . $type]) }}>
{{ $slot }}
</div>
{{-- Using it in any view --}}
<x-alert type="success">Post saved successfully!</x-alert>
<x-alert type="danger" class="mt-3">Something went wrong.</x-alert>
{{-- Output HTML --}}
{{-- <div class="alert alert-success">Post saved successfully!</div> --}}
{{-- <div class="alert alert-danger mt-3">Something went wrong.</div> --}}
type becomes a prop, the text between the tags becomes $slot, and the extra class="mt-3" is merged into the class list.