Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
A909M committed Jan 6, 2025
1 parent 6564822 commit af13f94
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
70 changes: 61 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Effortlessly generate reusable form fields and table column helpers for Filament resources based on Laravel models, streamlining your development workflow.

# Filament-Generate-Helpers
[![Latest Version on Packagist](https://img.shields.io/packagist/v/a909m/filament-generate-helpers.svg?style=flat-square)](https://packagist.org/packages/a909m/filament-generate-helpers)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/a909m/filament-generate-helpers/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/a909m/filament-generate-helpers/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/a909m/filament-generate-helpers/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/a909m/filament-generate-helpers/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/a909m/filament-generate-helpers.svg?style=flat-square)](https://packagist.org/packages/a909m/filament-generate-helpers)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Effortlessly generate reusable form fields and table column helpers for Filament resources based on Laravel models, streamlining your development workflow.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/Filament-Generate-Helpers.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/Filament-Generate-Helpers)
## Features

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
- Automatically generates reusable **form fields** and **table columns**.
- Organizes fields and columns into traits and a helper class.
- Simplifies resource management for Filament developers.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

Expand All @@ -26,11 +25,64 @@ composer require a909m/filament-generate-helpers

## Usage

To Generate a Helpers for the `App\Models\User`model, run:
```php
$filamentGenerateHelpers = new A909M\FilamentGenerateHelpers();
echo $filamentGenerateHelpers->echoPhrase('Hello, A909M!');
php artisan filament-generate-helpers:run User
```
This will create the following files under the `app/Filament/Helpers/User` directory:

```
.
+-- Helpers
| +-- User
| | +-- UserHelper.php
| | +-- Traits
| | | +-- UserFormFields.php
| | | +-- UserTableColumns.php
```
# Under the Hood
The generated helpers are similar to Filament's [Automatically generating forms and tables](https://filamentphp.com/docs/3.x/panels/resources/getting-started#automatically-generating-forms-and-tables)
but are grouped into traits for better reusability. For example, for the `User` model:

```
<?php
namespace App\Filament\Helpers\User;
use App\Filament\Helpers\User\Traits\UserFormFields;
use App\Filament\Helpers\User\Traits\UserTableColumns;
class UserHelper
{
use UserFormFields ,UserTableColumns;
public static function formFields(): array
{
return [
static::nameField(),
static::emailField(),
static::emailVerifiedAtField(),
static::passwordField(),
];
}
public static function tableColumns(): array
{
return [
static::nameColumn(),
static::emailColumn(),
static::emailVerifiedAtColumn(),
static::createdAtColumn(),
static::updatedAtColumn(),
];
}
}
```
# Benefits
- Separation of Concerns: Fields and columns are neatly organized into traits.
- Reusability: The helper and traits can be reused across multiple resources.
- Customization: Easily modify the generated traits and helper classes.
## Testing

```bash
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Concerns/CanGenerateFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ protected function getResourceFormSchema(string $model, bool $isFunCall = false)
if ($isFunCall) {

foreach ($components as $componentName => $componentData) {

$output .= "static::{$componentName}Field(),";
$functionName = Str::camel("{$componentName}Field");
$output .= "static::{$functionName}(),";
$output .= PHP_EOL;
}

Expand All @@ -142,7 +142,7 @@ protected function getResourceFormSchema(string $model, bool $isFunCall = false)
foreach ($components as $componentName => $componentData) {
// Constructor
$Prototype = (string) str($componentData['type']);
$functionName = "{$componentName}Field";
$functionName = Str::camel("{$componentName}Field");
$output .= PHP_EOL;
$output .= '/**'.PHP_EOL;
$output .= " * {$functionName}".PHP_EOL;
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Concerns/CanGenerateTablesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ protected function getResourceTableColumns(string $model, bool $isFunCall = fals
if ($isFunCall) {
// code...
foreach ($columns as $columnName => $columnData) {

$output .= "static::{$columnName}Column(),";
$functionName = Str::camel("{$columnName}Column");
$output .= "static::{$functionName}(),";
$output .= PHP_EOL;
}

Expand All @@ -141,7 +141,7 @@ protected function getResourceTableColumns(string $model, bool $isFunCall = fals
foreach ($columns as $columnName => $columnData) {
// Constructor
$Prototype = (string) str($columnData['type']);
$functionName = "{$columnName}Column";
$functionName = Str::camel("{$columnName}Column");
$output .= PHP_EOL;
$output .= '/**'.PHP_EOL;
$output .= " * {$functionName}".PHP_EOL;
Expand Down

0 comments on commit af13f94

Please sign in to comment.