定制 androlax2/laravel-model-typed-settings 二次开发

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

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

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

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

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固