Hopp til innholdet

Aurora 1.0: install it into any Laravel site, with passkeys and two-factor sign-in.

What's new →

Dokumentasjon

Lage blokker

Skriv en blokk: en PHP-klasse, en Blade-visning og én linje for å registrere den.

A block is two files: a class that describes it (its fields, defaults and what the AI should know) and a Blade view that draws it. The same view renders on your website, in the visual editor and in previews. php artisan aurora:make-block Quote creates both, ready to fill in.

1. The class

app/Blocks/QuoteBlock.php PHP
namespace App\Blocks;

use Aurora\Blocks\Block;
use Aurora\Blocks\Editable;
use Filament\Forms\Components\TextInput;

class QuoteBlock extends Block
{
    public static function type(): string
    {
        return 'quote';
    }

    public static function label(): string
    {
        return __('Quote');
    }

    public static function description(): string
    {
        return __('A short quote with who said it.');
    }

    public static function defaults(): array
    {
        return ['quote' => 'Simple things should be simple.', 'author' => 'Alan Kay'];
    }

    public static function editables(): array
    {
        return ['quote' => Editable::text()->multiline()];
    }

    public static function schema(): array
    {
        return [
            TextInput::make('quote')->label(__('Quote')),
            TextInput::make('author')->label(__('Who said it')),
        ];
    }
}

2. The view

An anonymous component named after the block's type. Mark text editors can change on the canvas with @editable.

resources/views/components/blocks/quote.blade.php Blade
@props(['data' => []])

<figure class="rounded-2xl bg-zinc-50 p-8">
    <blockquote class="text-2xl font-semibold" @editable('quote')>{{ $data['quote'] ?? '' }}</blockquote>
    <figcaption class="mt-4 text-zinc-500">{{ $data['author'] ?? '' }}</figcaption>
</figure>

3. Its place in the palette

Blocks in app/Blocks are found on their own: there is nothing to register. To choose where they sit in the block palette, list them in your service provider; the rest follow.

app/Providers/AppServiceProvider.php PHP
use Aurora\Blocks\Blocks;

public function boot(): void
{
    Blocks::register([
        HeroBlock::class,
        QuoteBlock::class,
    ]);
}

Det var det

Blokken ligger nå i editorens palett, i katalogen til KI-assistenten og MCP-verktøyene, og tekstfeltene kan oversettes.

Blocks that hold blocks

A section, a grid or a row of buttons implements Aurora\Blocks\Contracts\Container and draws each slot with Blocks::slot('name'). Use Blocks::isEditing() in a view to skip animations or show placeholders while someone is editing.