承接 pkalusek/laravel-model-settings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pkalusek/laravel-model-settings

最新稳定版本:1.0.1

Composer 安装命令:

composer require pkalusek/laravel-model-settings

包简介

Simplest way to store model-specific settings/preferences in Laravel

README 文档

README

Latest Version on Packagist Total Downloads

The simplest way to store model-specific settings/preferences in Laravel. This package allows you to easily attach customizable settings to any Eloquent model.

Installation

You can install the package via composer:

composer require pkalusek/laravel-model-settings

The package will automatically register itself via Laravel's package discovery.

Publish and run the migrations:

php artisan vendor:publish --tag="laravel-model-settings-migrations"
php artisan migrate

Usage

Add the HasSettings trait to any model you want to have settings:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Pkalusek\LaravelModelSettings\Traits\HasSettings;

class User extends Model
{
    use HasSettings;
    
    // ... your model code
}

Now you can easily get, set, and manage settings for your model:

$user = User::find(1);

// Set a setting
$user->settings->set('theme', 'dark');
$user->settings->set('notifications.email', true);
$user->settings->set('preferences.language', 'en');

// Get a setting
$theme = $user->settings->get('theme'); // 'dark'
$emailNotifications = $user->settings->get('notifications.email'); // true

// Get with default value
$language = $user->settings->get('preferences.language', 'en');

// Remove a setting
$user->settings->forget('theme');
$user->settings->forget('notifications.email');

Features

  • Simple API: Easy-to-use methods for getting, setting, and removing settings
  • Nested Settings: Support for dot notation for nested settings (e.g., notifications.email)
  • Default Values: Get settings with fallback default values
  • Automatic Cleanup: Empty nested objects are automatically removed
  • JSON Storage: Settings are stored as JSON in the database for flexibility
  • Polymorphic Relations: Each model instance has its own settings record

Testing

composer test

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-09