androlax2/laravel-model-typed-settings
最新稳定版本:0.1.0
Composer 安装命令:
composer require androlax2/laravel-model-typed-settings
包简介
A Laravel package that adds type-safe settings attributes to Eloquent models with automatic casting and validation
README 文档
README
Stop treating your model settings like messy associative arrays. This package allows you to cast JSON columns directly into Type-Safe DTOs with support for nested objects, enums, and automatic type coercion.
Installation
You can install the package via composer:
composer require androlax2/laravel-model-typed-settings
Usage
Define your Settings Class
Create a class that extends Androlax2\LaravelModelTypedSettings\Settings. Use standard PHP properties with types and default values.
<?php namespace App\Settings; use Androlax2\LaravelModelTypedSettings\Settings; use Androlax2\LaravelModelTypedSettings\Attributes\AsCollection; class UserPreferences extends Settings { public string $theme = 'light'; public int $items_per_page = 15; public bool $notifications_enabled = true; // Support for Backed Enums public UserStatus $status = UserStatus::Active; // Support for Collections of Enums #[AsCollection(NotificationChannel::class)] public array $channels = [NotificationChannel::Email]; // Support for Nested Settings public SecuritySettings $security; }
Apply to Eloquent Model
Add the settings class to your model's $casts array.
<?php use App\Models\User; use App\Settings\UserPreferences; class User extends Model { protected $casts = [ 'preferences' => UserPreferences::class, ]; }
Add to database the column for preferences :
<?php Schema::create('users', function (Blueprint $table) { $table->settingColumn('preferences'); });
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.
统计信息
- 总下载量: 1.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-02