androlax2/laravel-model-typed-settings

A Laravel package that adds type-safe settings attributes to Eloquent models with automatic casting and validation

Fund package maintenance!
Androlax2

Installs: 218

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/androlax2/laravel-model-typed-settings

0.1.0 2026-02-02 14:11 UTC

This package is auto-updated.

Last update: 2026-02-02 14:15:48 UTC


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.