# Blade Components

**Package:** Laravel Modules | **Version:** 3 | **URL:** https://mozex.dev/docs/laravel-modules/v3/features/blade-components

---

## Overview

Auto-discovers class-based Blade components within modules and registers them with namespaced aliases using the `<x-module::path.to.component/>` syntax.

## What gets discovered

- Non-abstract classes extending `Illuminate\View\Component`
- Located in directories matching configured patterns (default: `*/View/Components`)

## Default configuration

```php
'blade-components' => [
    'active' => true,
    'patterns' => [
        '*/View/Components',
    ],
],
```

## Directory layout

```
Modules/Blog/
└── View/
    └── Components/
        ├── Post/
        │   └── Card.php          // <x-blog::post.card />
        ├── Filter.php            // <x-blog::filter />
        └── WithoutView.php       // <x-blog::without-view />
```

## Naming rules

- Module name → kebab-case prefix: `Blog` → `blog`, `UserAdmin` → `user-admin`
- Path segments under the matched pattern → kebab-cased and dot-joined: `Post/Card.php` → `post.card`
- Fallback: if no path segments can be derived, the alias uses the lowercase class basename

## Usage

```blade
<x-blog::filter :name="$name" />
<x-blog::post.card :post="$post" />
```

Components can return any view from their `render()` method:

```php
class Card extends \Illuminate\View\Component
{
    public function __construct(public $post) {}

    public function render()
    {
        return view('blog::components.post.card');
    }
}
```

## Configuration

- Set `'blade-components.active' => false` to disable auto-registration.
- Edit `'blade-components.patterns'` to change discovery directories.

## Troubleshooting

- **Unknown tag**: clear compiled views (`php artisan view:clear`) and confirm the alias matches the kebab-cased path.
- **Alias collision**: if two classes across modules map to the same alias, rename one or adjust directory structure.

## See also

- [Views & Anonymous Components](https://mozex.dev/docs/laravel-modules/v3/features/views)

---

## Table of Contents

- [Introduction](https://mozex.dev/docs/laravel-modules/v3)
- [Support Us](https://mozex.dev/docs/laravel-modules/v3/support-us)
- [Requirements](https://mozex.dev/docs/laravel-modules/v3/requirements)
- [Changelog](https://mozex.dev/docs/laravel-modules/v3/changelog)
- [Contributing](https://mozex.dev/docs/laravel-modules/v3/contributing)
- [Questions & Issues](https://mozex.dev/docs/laravel-modules/v3/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/laravel-modules/v3/about)

### Features

- [Blade Components](https://mozex.dev/docs/laravel-modules/v3/features/blade-components)
- [Views](https://mozex.dev/docs/laravel-modules/v3/features/views)
- [Routes](https://mozex.dev/docs/laravel-modules/v3/features/routes)
- [Configs](https://mozex.dev/docs/laravel-modules/v3/features/configs)
- [Migrations](https://mozex.dev/docs/laravel-modules/v3/features/migrations)
- [Seeders](https://mozex.dev/docs/laravel-modules/v3/features/seeders)
- [Commands](https://mozex.dev/docs/laravel-modules/v3/features/commands)
- [Helpers](https://mozex.dev/docs/laravel-modules/v3/features/helpers)
- [Models & Factories](https://mozex.dev/docs/laravel-modules/v3/features/models-factories)
- [Policies](https://mozex.dev/docs/laravel-modules/v3/features/policies)
- [Events & Listeners](https://mozex.dev/docs/laravel-modules/v3/features/events-listeners)
- [Service Providers](https://mozex.dev/docs/laravel-modules/v3/features/service-providers)
- [Translations](https://mozex.dev/docs/laravel-modules/v3/features/translations)
- [Caching](https://mozex.dev/docs/laravel-modules/v3/features/caching)
- [Listing Modules](https://mozex.dev/docs/laravel-modules/v3/features/listing)
- [Livewire Components](https://mozex.dev/docs/laravel-modules/v3/features/livewire-components)
- [Filament](https://mozex.dev/docs/laravel-modules/v3/features/filament)
- [Nova Resources](https://mozex.dev/docs/laravel-modules/v3/features/nova-resources)

### Integrations

- [PHPStan](https://mozex.dev/docs/laravel-modules/v3/integrations/phpstan)
- [PHPUnit](https://mozex.dev/docs/laravel-modules/v3/integrations/phpunit)
- [Pest](https://mozex.dev/docs/laravel-modules/v3/integrations/pest)