定制 hungrybus/filament-custom-fields 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hungrybus/filament-custom-fields

最新稳定版本:0.2.1

Composer 安装命令:

composer require hungrybus/filament-custom-fields

包简介

This plugin allows to create custom fields via front-end

README 文档

README

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

Filament Custom Fields is a plugin for Laravel Filament that allows you to add custom fields to your Filament resources.

Installation

You can install the package via composer:

composer require hungrybus/filament-custom-fields

You can publish and run the migrations with:

php artisan vendor:publish --provider="HungryBus\FilamentCustomFields\FilamentCustomFieldsServiceProvider"

After publishing the migration files, run the migrations:

php artisan migrate

Configuration

The package provides a configuration file located at config/custom-fields.php. In this file, you can specify the resources and models that will utilize custom fields. For example:

<?php

use HungryBus\FilamentCustomFields\Resources\CustomFieldResource;
use HungryBus\FilamentCustomFields\Resources\CustomFieldResponseResource;

return [
    'resources' => [
        CustomFieldResource::class,
        CustomFieldResponseResource::class,
    ],
    
    // Models that will have custom fields
    'models' => [
        // \App\Models\YourModel::class => 'your_model',
    ],
    
    'navigation_group' => 'Custom Fields',
    
    'custom_fields_label' => 'Custom Fields',
    
    'custom_field_responses_label' => 'Custom Field Responses',
];

Usage

In order to save and/or display custom fields for a model, you need to add the HasCustomData trait to the model:

use HungryBus\FilamentCustomFields\Traits\HasCustomData;

class Vehicle extends Model
{
    use HasCustomData;
}

If you have multi-tenancy enabled, you can specify the tenant column in the model:

// Company is a tenant model
class Company extends \Illuminate\Database\Eloquent\Model
{
    use \HungryBus\CustomFields\Concerns\HasTenantCustomFields;
}

Displaying Custom Field Responses

To display custom field responses in a resource's table, add the custom fields column:

use HungryBus\FilamentCustomFields\CustomFields\FilamentCustomFieldsHelper;

public static function table(Table $table): Table
{
    $columns = [
        // Your existing columns
    ];

    return $table
        ->columns([
            // Your existing columns
            FieldsService::buildTable(Vehicle::class, $columns))
        ]);
}

Displaying Custom Field Responses in a Form

To display custom field responses in a form, add the custom fields to the form:

return $form->schema([
    // Your existing fields
    \HungryBus\CustomFields\Services\FieldsService::buildForm(Vehicle::class)
]);

In Create page, add the CreatesWithCustomData trait to the resource:

class CreateVehicle extends \Filament\Resources\Pages\CreateRecord
{
    use CreatesWithCustomData;
}

Then, in the Edit page, add the UpdatesWithCustomData trait to the resource:

class EditVehicle extends \Filament\Resources\Pages\EditRecord
{
    use UpdatesWithCustomData;
}

Displaying Custom Field Responses in Infolist

To display custom field responses in an infolist, add the custom fields to the infolist:

return $infolist->schema([
    // Your existing fields
    \HungryBus\CustomFields\Services\FieldsService::buildInfolist(Vehicle::class)
]);

Credits

This package is developed and maintained by HungryBus.

Disclaimer

This is my very first open-source package. I am still learning the open-source topic, and I am open to any constructive feedback or suggestions. Please feel free to open an issue to express an opinion or ask a question. If you think you can help this package to grow, please feel free to open a pull request.

Due to my job and some personal stuff, I am extremely busy at the moment, and it is quite hard to me to find time to work on this on everyday basis. I will try to find time to work on this package as much as I can.

License

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

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-19