InterNACHI / modular

Modularize your Laravel application
MIT License
800 stars 65 forks source link

Filament Support #67

Open AshrafBasry opened 9 months ago

AshrafBasry commented 9 months ago

Is there will be support for filament commands like php artisan make:filament-panel Admin --module=Module ?

51

WebKenth commented 6 months ago

Just my 5 cents here

if you create a FilamentPlugin file filament will automatically handle your app-modules

You can make a FilamentPlugin file in app-modules/<your-module>/src

Example file:

<?php

namespace Vendor\Module;

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

class <MODULE>FilamentPlugin implements Plugin
{

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

    public function getId(): string
    {
        return 'vendor-module';
    }

    public function register(Panel $panel): void
    {
        $panel->discoverResources(in: base_path('app-modules/<your-module>/src/Filament/Resources'), for: 'VENDOR\\MODULE\\Filament\\Resources');
    }

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

    public static function get(): static
    {
        /** @var static $plugin */
        $plugin = filament(app(static::class)->getId());

        return $plugin;
    }
}

Then add this to your panel in the ->plugins([ \<VENDOR>\<MODULE>\<MODULE>FilamentPlugin::make() ]) array

Any filament command like php artisan make:filament-resource Customer will now ask you where you want to make it and if you pick your plugin it auto places it in to the module