skylence/laravel-custom-fields 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

skylence/laravel-custom-fields

最新稳定版本:v1.2.2

Composer 安装命令:

composer require skylence/laravel-custom-fields

包简介

Dynamic custom fields for Laravel Eloquent models with Filament integration

README 文档

README

Latest Version on Packagist Total Downloads

A powerful Laravel package that allows you to dynamically add custom fields to any Eloquent model without modifying your database schema or codebase. Built with Livewire 3 for a modern, reactive admin interface.

Features

  • 11 Field Types: Text, Textarea, Select, Radio, Checkbox, Toggle, Checkbox List, DateTime, Rich Editor, Markdown, Color Picker
  • Column-Based Storage: Custom fields are stored as actual database columns for optimal performance
  • Livewire 3 UI: Modern, reactive admin interface for managing custom fields
  • Simple Integration: Just add a trait to your models
  • Automatic Column Management: Database columns are created/deleted automatically
  • Soft Deletes: Safe deletion with optional permanent removal
  • Searchable & Filterable: Built-in search and filtering in the admin interface
  • Sortable Fields: Control the display order of your custom fields
  • Validation Support: Full Laravel validation rule support
  • Multi-Model Support: Add custom fields to multiple models

Installation

You can install the package via composer:

composer require xve/laravel-custom-fields

Run the migrations:

php artisan migrate

That's it! The package works out of the box with sensible defaults.

Optional: Publish Configuration

You only need to publish the config if you want to customize routes, middleware, or other settings:

php artisan vendor:publish --tag="custom-fields-config"

Optional: Publish Views

You only need to publish views if you want to customize the admin interface:

php artisan vendor:publish --tag="custom-fields-views"

Configuration

The package works with sensible defaults. If you've published the config file, it's located at config/custom-fields.php:

return [
    // Route configuration (default: /admin/fields with web & auth middleware)
    'route' => [
        'prefix' => 'admin/fields',
        'middleware' => ['web', 'auth'],
        'name_prefix' => 'custom-fields.',
    ],

    // Database table name (default: custom_fields)
    'table_name' => 'custom_fields',

    // Models that can have custom fields (optional - for UI dropdown)
    'customizable_types' => [
        // Example: App\Models\User::class => 'Users',
        // Example: App\Models\Post::class => 'Posts',
    ],

    // Pagination (default: 15)
    'per_page' => 15,

    // Enable soft deletes (default: true)
    'enable_soft_deletes' => true,

    // Enable default option selection (default: true)
    'enable_default_options' => true,
];

Usage

Step 1: Add Trait to Your Model

Add the HasCustomFields trait to any model you want to support custom fields:

use Illuminate\Database\Eloquent\Model;
use Skylence\LaravelCustomFields\Traits\HasCustomFields;

class Employee extends Model
{
    use HasCustomFields;

    protected $fillable = [
        'name',
        'email',
        // Custom field codes will be automatically merged
    ];
}

Step 2: Create Custom Fields via Admin Interface

Navigate to /admin/fields in your browser to access the custom fields management interface.

Create a new field:

  1. Click "Create New Field"

  2. Fill in the details:

    • Name: Display label (e.g., "Employee Rating")
    • Code: Database column name (e.g., "employee_rating")
    • Type: Select from 11 field types
    • Model Type: Select which model this field belongs to
    • Options: Add options for select/radio/checkbox list types
    • Display Settings: Toggle "Show in table columns"
  3. Click "Create Field"

The package will automatically:

  • Create a database column on the model's table
  • Make the field available in your model
  • Add appropriate casts and fillable attributes

Step 3: Use Custom Fields in Your Code

Once created, custom fields work like regular model attributes:

// Create a new record with custom fields
$employee = Employee::create([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'employee_rating' => 'Excellent', // Custom field
    'department_code' => 'IT',         // Custom field
]);

// Update custom fields
$employee->employee_rating = 'Good';
$employee->save();

// Access custom field values
echo $employee->employee_rating; // 'Good'

// Use helper methods
$rating = $employee->getCustomField('employee_rating');
$employee->setCustomField('employee_rating', 'Excellent');

// Get all custom field values
$customValues = $employee->getCustomFieldValues();

Step 4: Query with Custom Fields

Custom fields are stored as actual database columns, so you can use them in queries:

// Where clauses
$employees = Employee::where('employee_rating', 'Excellent')->get();

// Order by
$employees = Employee::orderBy('department_code')->get();

// Select specific fields
$employees = Employee::select('name', 'employee_rating')->get();

Field Types

The package supports 11 different field types:

  • Text Input: Basic text with subtypes (email, numeric, integer, password, tel, url)
  • Textarea: Multi-line text
  • Select Dropdown: Single or multi-select with custom options
  • Radio Buttons: Mutually exclusive options
  • Checkbox: Single boolean checkbox
  • Toggle: Toggle switch (boolean)
  • Checkbox List: Multiple checkboxes (array)
  • Date & Time: DateTime picker
  • Rich Text Editor: WYSIWYG editor
  • Markdown Editor: Markdown with preview
  • Color Picker: Color selection

Admin Interface Routes

The package provides three main routes:

  • Index: /admin/fields - List all custom fields
  • Create: /admin/fields/create - Create a new custom field
  • Edit: /admin/fields/{field}/edit - Edit an existing custom field

All routes are protected by the middleware specified in the config file (default: ['web', 'auth']).

Programmatic Field Creation

You can also create fields programmatically:

use Skylence\LaravelCustomFields\Models\Field;

Field::create([
    'name' => 'Employee Rating',
    'code' => 'employee_rating',
    'type' => 'select',
    'options' => ['Excellent', 'Good', 'Average', 'Poor'],
    'customizable_type' => App\Models\Employee::class,
    'use_in_table' => true,
    'sort' => 10,
]);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

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.

skylence/laravel-custom-fields 适用场景与选型建议

skylence/laravel-custom-fields 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.3k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「custom-fields」 「filament」 「laravel-custom-fields」 「skylence」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 skylence/laravel-custom-fields 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 skylence/laravel-custom-fields 我们能提供哪些服务?
定制开发 / 二次开发

基于 skylence/laravel-custom-fields 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-14