peltonsolutions/filament-enums
最新稳定版本:1.2.0
Composer 安装命令:
composer require peltonsolutions/filament-enums
包简介
A custom package for Filament for handling enum values in Filament Admin.
README 文档
README
filament-enums is an extension to the peltonsolutions/laravel-enums package, designed specifically for Laravel developers. This package simplifies working with enumerated values in your Filament applications, thus enhancing the readability and maintainability of your code.
Like the laravel-enums package, filament-enums supports the use of named constants, improving the organization and clarity of your code. It leverages the features provided by laravel-enums, complementing them with additional functionalities tailored for Filament.
Optionally, this package allows you to make your Enum fields nullable through the NullableEnum class extension.
Install
You can install the package via composer using the following command:
composer require peltonsolutions/filament-enums
Example:
class ContentPageStatus extends \PeltonSolutions\LaravelEnums\Models\Enum { const DRAFT = 'draft'; const SCHEDULED = 'scheduled'; const PUBLISHED = 'published'; const ARCHIVED = 'archived'; public static function map(): array { return [ static::DRAFT => trans('content_page.statuses.draft'), static::SCHEDULED => trans('content_page.statuses.scheduled'), static::PUBLISHED => trans('content_page.statuses.published'), static::ARCHIVED => trans('content_page.statuses.archived'), ]; } }
class ContentPage extends Model { protected $casts = [ 'status' => ContentPageStatus::class ]; }
class ContentPageResource extends Resource { protected static ?string $model = ContentPage::class; public static function form(Form $form): Form { return $form ->schema([ \PeltonSolutions\FilamentEnums\Models\Forms\Components\EnumSelect::make('status') ->default(ContentPageStatus::DRAFT); } }
This will create a Select component that:
- Gives options from the
map()function - Makes the field required if it's not
\PeltonSolutions\LaravelEnums\Models\NullableEnum - Requires that the selected value matches one of the
map()keys
Testing
To ensure that laravel-enums is functioning correctly, you can run the package's tests using:
NOTE: Tests are WIP. Having troubles writing tests that require the $record to tbe passed into the closures.
composer test
Security
If you discover any security-related issues, please email security@peltonsolutions.com instead of using the issue tracker.
Credits
License
filament-enums is open-sourced software. It's licensed under the MIT license, which is a permissive license allowing the software to be used, modified, and shared.
统计信息
- 总下载量: 144
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-05