PHPackages                             a909m/filament-generate-helpers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. a909m/filament-generate-helpers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

a909m/filament-generate-helpers
===============================

Effortlessly generate reusable form fields and table column helpers for Filament resources based on Laravel models, streamlining your development workflow.

1.1.0(1y ago)24918[4 PRs](https://github.com/A909M/Filament-Generate-Helpers/pulls)MITPHPPHP ^8.2CI passing

Since Jan 6Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/A909M/Filament-Generate-Helpers)[ Packagist](https://packagist.org/packages/a909m/filament-generate-helpers)[ Docs](https://github.com/a909m/filament-generate-helpers)[ GitHub Sponsors](https://github.com/A909M)[ RSS](/packages/a909m-filament-generate-helpers/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (12)Versions (10)Used By (0)

[![Stand With Palestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/banner-no-action.svg)](https://TheBSD.github.io/StandWithPalestine/)

Filament-Generate-Helpers
=========================

[](#filament-generate-helpers)

[![StandWithPalestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/badges/StandWithPalestine.svg)](https://github.com/TheBSD/StandWithPalestine/blob/main/docs/README.md)[![Latest Version on Packagist](https://camo.githubusercontent.com/1f6b7b88e4f6dfe047e46e497768587d387fafc54047f79a2d84e79c261a2f87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f613930396d2f66696c616d656e742d67656e65726174652d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/a909m/filament-generate-helpers)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9c5a7276674b681e518c736e69ad6939f0380b343d53924e3233c6f4cbba8209/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f613930396d2f66696c616d656e742d67656e65726174652d68656c706572732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/a909m/filament-generate-helpers/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8572db54fdbc330f168e1415f085290885e73c00a5cde5bab7a9ca11282452a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f613930396d2f66696c616d656e742d67656e65726174652d68656c706572732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/a909m/filament-generate-helpers/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/dcc37ab1e21f6633803105d02de308724fb314a157641192e94f0fca09130c7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f613930396d2f66696c616d656e742d67656e65726174652d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/a909m/filament-generate-helpers)

Effortlessly create reusable form fields and table column helpers for Filament resources based on Laravel models. This package is not just about generating code—it introduces a methodology for managing forms and tables in your Filament projects, making them reusable and easier to maintain.

---

Why Use This Package?
---------------------

[](#why-use-this-package)

When building a Filament project, it's common to encounter repetitive definitions for **forms** and **tables** in various contexts, such as:

- **Resources**: A resource's form and table are defined independently.
- **Relation Managers**: You might reuse a form or table inside a relation manager.
- **Table widgets or Custom Pages**: Forms and tables are often replicated here.
- **Select Forms (`createOptionForm`)**: Similar forms might be required when creating options in a `Select` field.

### The Problem

[](#the-problem)

If a change is required in the form or table (e.g., adding a new field or column), you have to update it in multiple places. This is time-consuming, error-prone, and violates the **DRY (Don't Repeat Yourself)** principle.

### The Solution

[](#the-solution)

This package provides a systematic approach:

- Centralizes the definitions of **form fields** and **table columns** in reusable traits and helper classes.
- Allows you to make changes in **one place** and have them reflected everywhere.

---

Features
--------

[](#features)

- **Reusable Form Fields**: Generate reusable form fields organized into a trait.
- **Reusable Table Columns**: Generate reusable table columns organized into a trait.
- **Centralized Customization**: Changes to the traits automatically propagate across all resources, relation managers, Table widgets, etc.
- **Seamless Integration**: Works effortlessly with Filament's workflow.

---

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require a909m/filament-generate-helpers
```

Usage
-----

[](#usage)

### Step 1: Generate Helpers

[](#step-1-generate-helpers)

To generate helpers for a model, use the following Artisan command:

```
php artisan filament-generate-helpers:run User
```

Under the hood, this command leverages Filament's built-in feature for automatically generating forms and tables. You can learn more about this feature in the [Filament documentation](https://filamentphp.com/docs/3.x/panels/resources/getting-started#automatically-generating-forms-and-tables).

This will create the following structure in your `app/Filament/Helpers` directory:

```
.
+-- Helpers
|   +-- User
|   |   +-- UserHelper.php
|   |   +-- Traits
|   |   |   +-- UserFormFields.php
|   |   |   +-- UserTableColumns.php

```

### Step 2: Use the Helpers

[](#step-2-use-the-helpers)

In your Filament resources, relation managers, Table widgets, or any other context, you can reuse the generated helpers.

**Example:** Using Helpers in a Resource

```
namespace App\Filament\Resources\UserResource;

use App\Filament\Helpers\User\UserHelper;
use Filament\Resources\Resource;

class UserResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form->schema(
            UserHelper::formFields()
        );
    }

    public static function table(Table $table): Table
    {
        return $table->columns(
            UserHelper::tableColumns()
        );
    }
}
```

How It Works
------------

[](#how-it-works)

The package organizes the generated code into a helper class and two traits:

1. **Helper Class:** Combines and exposes reusable methods for form fields and table columns.
2. **Traits:** Separately define reusable form fields and table columns.

### Generated Helper Example

[](#generated-helper-example)

**For the `User` model:**

```
