https://github.com/codewithdennis/filament-factory-action
This plugin adds a new feature to the Filament admin panel table, enabling easy generation of test records for your database tables using your Laravel Factory definitions.
https://github.com/codewithdennis/filament-factory-action
Last synced: 3 months ago
JSON representation
This plugin adds a new feature to the Filament admin panel table, enabling easy generation of test records for your database tables using your Laravel Factory definitions.
- Host: GitHub
- URL: https://github.com/codewithdennis/filament-factory-action
- Owner: CodeWithDennis
- License: mit
- Created: 2023-10-10T17:27:28.000Z (over 1 year ago)
- Default Branch: 3.x
- Last Pushed: 2025-03-19T07:41:23.000Z (3 months ago)
- Last Synced: 2025-04-09T21:19:10.441Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 48.8 KB
- Stars: 35
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Filament Factory Action
[](https://packagist.org/packages/codewithdennis/filament-factory-action)
[](https://packagist.org/packages/codewithdennis/filament-factory-action)
This plugin adds a new feature to the Filament admin panel table, enabling easy generation of test records for your database tables using your Laravel Factory definitions.
_This plugin extends the standard Filament action, ensuring that you can continue to utilize all the methods that are typically available within the action class_
## Installation
You can install the package via composer:```bash
composer require codewithdennis/filament-factory-action
```## Usage Example
Prior to utilizing this action, it is essential to ensure that you have set up a [factory](https://laravel.com/docs/10.x/eloquent-factories) for your model.
```php
class ProfileFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->company(),
'is_public' => rand(0, 1),
];
}
}
````Suppose you already possess a `ProfileResource` within the Filament framework. You can integrate the action into the ListProfiles class, as demonstrated in the following example.
```php
FactoryAction::make(),
``````PHP
use App\Filament\Resources\ProfileResource;
use CodeWithDennis\FactoryAction\FactoryAction;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;class ListProfiles extends ListRecords
{
protected static string $resource = ProfileResource::class;protected function getHeaderActions(): array
{
return [
FactoryAction::make()
->color('danger')
// ->slideOver()
->icon('heroicon-o-wrench'),
Actions\CreateAction::make()
];
}
}
```You can create/attach relational records with the following example. Just make certain that these models also possess their respective factories
```PHP
protected function getHeaderActions(): array
{
return [
FactoryAction::make()
// If you want to create or create and attach you can do so using `hasMany`
->hasMany([Badge::class, Category::class])
// If you want to attach existing models you can do so using `belongsToMany`
->belongsToMany([Badge::class, Category::class]),
];
}
```The default behavior is to hide the action in production environments, but you can override this by using your own logic:
```php
->hidden(fn() => false)
```## Showcase
![]()
![]()
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [CodeWithDennis](https://github.com/CodeWithDennis)
- [Adam Weston](https://github.com/awcodes)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.