coolsam/visual-forms

Dynamically and Visually create forms in Filament and collect responses

Fund package maintenance!
coolsam

v0.1.1 2025-03-11 07:34 UTC

This package is auto-updated.

Last update: 2025-03-14 21:04:59 UTC


README

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

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require coolsam/visual-forms
php artisan visual-forms:install

Follow the installation instructions to:

  1. publish the config file
  2. publish the migrations
  3. run the migrations (Optional)

You can run the above steps manually by running the following commands:

To publish the migrations and run them

php artisan vendor:publish --tag="visual-forms-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="visual-forms-config"

This is the contents of the published config file:

return [
    'tables' => [
        'visual_forms' => env('VISUAL_FORMS_TABLE', 'visual_forms'),
        'visual_form_fields' => env('VISUAL_FORM_FIELDS_TABLE', 'visual_form_fields'),
        'visual_form_entries' => env('VISUAL_FORM_ENTRIES_TABLE', 'visual_form_entries'),
    ],
    'models' => [
        'visual_form' => env('VISUAL_FORM_MODEL', \Coolsam\VisualForms\Models\VisualForm::class),
        'visual_form_field' => env('VISUAL_FORM_FIELD_MODEL', \Coolsam\VisualForms\Models\VisualFormField::class),
        'visual_form_entry' => env('VISUAL_FORM_ENTRY_MODEL', \Coolsam\VisualForms\Models\VisualFormEntry::class),
    ],
];

Usage

  1. Register the VisualFormsPlugin in your AdminServiceProvider
use Coolsam\VisualForms\Filament\VisualFormsPlugin;

// in your register method
$panel->plugin(VisualFormsPlugin::class);

The above command will register the VisualForms resource for managing forms from your backend.

  1. In any of your forms, use the created form's schema to render it
use Coolsam\VisualForms\Models\VisualForm;

// in your form's schema
public function form(Form $form)
{
   $recordId = 1;
    $formModel = VisualForm::find($recordId);
    return $form->schema($formModel->schema());
}
  1. To save the form's response payload, execute the following method in your action method:
use Coolsam\VisualForms\Models\VisualForm;

// in your form's action method e.g create()
public function create(Request $request, VisualForm $record)
{
    $data = $this->form->getState();
    $record->recordSubmission($data, isProcessed: false);
    // TODO: you can send this payload wherever else you want, even to a webhook for further processing   
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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