New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

androlax2/laravel-model-typed-settings

A Laravel package that adds type-safe settings attributes to Eloquent models with automatic casting and validation
2,229 1
Install
composer require androlax2/laravel-model-typed-settings
Latest Version:0.1.0
PHP:^8.3
Laravel:11 · 12
License:MIT
Last Updated:Nov 12, 2026
Links: GitHub  ·  Packagist
Maintainer: Androlax2

Laravel Model Typed Settings

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.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

655,942,320 9,702
laravel/framework

The Laravel Framework.

617,629,957 34,997
laravel/tinker

Powerful REPL for the Laravel framework.

524,145,802 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

442,489,569 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

418,503,470 4,663

Version History

Version Released PHP Laravel License
0.1.0 ^8.3 ^11.0||^12.0 MIT