Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,85 @@ at:

You could access those translations with: `__('demo::messages.welcome');`

### Filament

Filament resources, pages, and widgets can live inside a module. Create a
[Filament plugin](https://filamentphp.com/docs/5.x/advanced/modular-architecture) in your module
that discovers the module's Filament classes, and register that plugin in your panel:

```php
// app-modules/blog/src/BlogPlugin.php
namespace Modules\Blog;

use Filament\Contracts\Plugin;
use Filament\Panel;

class BlogPlugin implements Plugin
{
public static function make(): static
{
return app(static::class);
}

public function getId(): string
{
return 'blog';
}

public function register(Panel $panel): void
{
$panel
->discoverResources(
in: __DIR__.'/Filament/Resources',
for: 'Modules\\Blog\\Filament\\Resources',
)
->discoverPages(
in: __DIR__.'/Filament/Pages',
for: 'Modules\\Blog\\Filament\\Pages',
)
->discoverWidgets(
in: __DIR__.'/Filament/Widgets',
for: 'Modules\\Blog\\Filament\\Widgets',
);
}

public function boot(Panel $panel): void
{
}
}
```

```php
// app/Providers/Filament/AdminPanelProvider.php
$panel->plugins([
\Modules\Blog\BlogPlugin::make(),
]);
```

Filament's `make:filament-*` commands don't accept `--module`, but once the plugin is registered they
will ask where to create the file, and you can pick your module's plugin.

### Livewire

Livewire's `make:livewire` command doesn't support the `--module` option. Create the component
class in your module manually and register it from your module's service provider. Modules created
with `make:module` already have one, and Laravel loads it through package discovery (it is listed
under `extra.laravel.providers` in the module's `composer.json`), so there is nothing else to register:

```php
// app-modules/blog/src/Providers/BlogServiceProvider.php
use Livewire\Livewire;
use Modules\Blog\Livewire\EditPost;

public function boot(): void
{
Livewire::component('blog::edit-post', EditPost::class);
}
```

You can then render it with `<livewire:blog::edit-post />`, and point the component's `render()`
method at a module view such as `view('blog::livewire.edit-post')`.

### Customizing the Default Module Structure

When you call `make:module`, Modular will scaffold some basic boilerplate for you. If you
Expand Down