Download the PHP package stechstudio/laravel-settings without Composer
On this page you can find all versions of the php package stechstudio/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stechstudio/laravel-settings
More information about stechstudio/laravel-settings
Files in stechstudio/laravel-settings
Package laravel-settings
Short Description Polymorphic, typed key/value settings for any Eloquent model.
License MIT
Homepage https://github.com/stechstudio/laravel-settings
Informations about the package laravel-settings
Laravel Settings
Polymorphic, typed key/value settings for any Eloquent model.
Drop the HasSettings trait onto any model and instantly get a bag of settings stored in a single polymorphic table. Values keep their PHP type — booleans come back as booleans, arrays as arrays, integers as integers — without you having to think about casting.
Installation
Publish and run the migration:
The package auto-registers its service provider. The migration is also loaded automatically, so in development you can migrate without publishing — publish it when you want the file committed to your app.
Optionally publish the config:
Usage
Add the trait to any model:
Reading & writing
Type casting
Types are detected automatically on write (bool, int, float, array, string). Pass an explicit cast as the third argument when you need to override detection — for example to store a numeric string as a string:
Available casts: Setting::CAST_STRING, CAST_INT, CAST_FLOAT, CAST_BOOL, CAST_ARRAY, CAST_JSON.
The relationship
HasSettings adds a standard settings() morph-many relationship, so you can eager load and query it like any other:
Settings are scoped to their owner — each model only ever sees its own.
Configuration
config/settings.php:
Testing
License
MIT. See LICENSE.md.
All versions of laravel-settings with dependencies
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0