ibrostudio/filament-plugin-tools

This is my package filament-plugin-tools

v1.0.1 2022-06-05 07:56 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

This package is for Filament plugin development.

It simply converts the native Filament commands to a plugin context to generate resources, pages and widgets.

Note

To get started easily, we released a Filament version of the Spatie's package-skeleton-laravel, including this tools and others goodies. Check it out here : filament-plugin-skeleton

Requirements

Let's say you are developing a plugin called PluginName. Files are located in a dedicated directory, called packages. You have locally imported the plugin in a Laravel app for development:

In composer.json:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/plugin-name"
        }
    ]
}

Then:

composer require vendor-name/plugin-name
Auto-registering

This package can auto-register resources, pages and widgets in your plugin service provider.

For that, ensure that:

  1. You added your service provider's fully qualified class name to the extra.laravel.providers array in your plugin's composer.json file:
{
    "extra": {
        "laravel": {
            "providers": [
                "VendorName\\PluginName\\PluginNameServiceProvider"
            ]
        }
    }
}
  1. Add the properties $pages, $resources and $widgets in the plugin's service provider file:
use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;

class PluginNameServiceProvider extends PluginServiceProvider
{
    protected array $pages = [
    ];

    protected array $resources = [
    ];

    protected array $widgets = [
    ];

    public function configurePackage(Package $package): void
    {
        $package->name('plugin-name');
    }
}

Installation

Install the filament-plugin-tools package in your Laravel app via composer:

composer require ibrostudio/filament-plugin-tools --dev

Usage

Resources
php artisan make:filament-plugin-resource plugin-name Model

The options work as with the original commands:

php artisan make:filament-plugin-resource plugin-name Model --simple
php artisan make:filament-plugin-resource plugin-name Model --generate
php artisan make:filament-plugin-resource plugin-name Model --view-page
etc...
Relation managers

All relations managers are availables:

php artisan make:filament-plugin-has-many ModelResource relationship attribute
php artisan make:filament-plugin-has-many-through ModelResource relationship attribute
php artisan make:filament-plugin-belongs-to-many ModelResource relationship attribute
php artisan make:filament-plugin-morph-many ModelResource relationship attribute
php artisan make:filament-plugin-morph-to-many ModelResource relationship attribute
Pages
php artisan make:filament-plugin-page plugin-name PageName

Options work too:

php artisan make:filament-plugin-page plugin-name Model --resource=ModelResource --type=custom
Widgets
php artisan make:filament-plugin-widget plugin-name WidgetName

With resource option:

php artisan make:filament-plugin-widget plugin-name Model --resource=ModelResource

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.