承接 codewithdennis/filament-factory-action 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codewithdennis/filament-factory-action

最新稳定版本:v3.0.3

Composer 安装命令:

composer require 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.

README 文档

README

Latest Version on Packagist Total Downloads

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:

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 for your model.

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.

FactoryAction::make(),
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

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:

->hidden(fn() => false)

Showcase

example-1 example-2 example-3

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.

统计信息

  • 总下载量: 8.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 37
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 37
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-11