Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
ij_javascript_use_double_quotes = false

[{composer.json,package.json}]
indent_style = space

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4']
laravel: ['11.*', '12.*', '13.*']

name: PHP ${{ matrix.php }} – Laravel ${{ matrix.laravel }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction

- name: Run tests
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

.phpstorm.meta.php
.DS_Store
.phpunit.result.cache
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You can change the configuration via the following environment variables:
| Variable | Description | Default |
|-----------------------------------|----------------------------------------------------------|-------------------------------|
| `MODEL_SETTINGS_TABLE` | The name of the table to store the model settings | `model_settings` |
| `MODEL_SETTINGS_SAVE_DEFAULT` | Whether to persist default values to the database | `false` |
| `MODEL_SETTINGS_CACHE_ENABLED` | Whether to enable caching for model settings | `false` |
| `MODEL_SETTINGS_CACHE_TTL` | The time to live for the model settings cache in seconds | `60 * 60 * 24 * 30` (30 days) |
| `MODEL_SETTINGS_CACHE_KEY_PREFIX` | The prefix for the model settings cache key | `model_settings` |
Expand Down Expand Up @@ -85,6 +86,8 @@ $user = User::find(1);
$theme = $user->getSetting('theme', 'light');
```

If `save_default` is enabled in the configuration (or via `MODEL_SETTINGS_SAVE_DEFAULT=true`), the default value will also be written to the database when the setting does not exist yet. This only applies when the default value is not `null`.

### Push a setting
You can push a setting by calling the `pushSetting` method on your model instance. This will append the value to the existing setting that is an array. For example:
```php
Expand Down
89 changes: 52 additions & 37 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
{
"name": "kaiserkiwi/model-settings",
"version": "1.2.0",
"description": "A simple way to manage settings in your Laravel models.",
"keywords": [
"laravel",
"settings",
"model",
"configuration"
],
"homepage": "https://github.com/kaiserkiwi/model-settings",
"license": "MIT",
"authors": [
{
"name": "Marco Kaiser",
"email": "marco@kaiser.kiwi"
}
],
"require": {
"php": "^8.0",
"illuminate/database": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0"
},
"require-dev": {
"hyperlinkgroup/pint": "^1.13"
},
"extra": {
"laravel": {
"providers": [
"Kaiserkiwi\\ModelSettings\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Kaiserkiwi\\ModelSettings\\": "src/"
}
}
"name": "kaiserkiwi/model-settings",
"version": "1.3.0",
"description": "A simple way to manage settings in your Laravel models.",
"keywords": [
"laravel",
"settings",
"model",
"configuration"
],
"homepage": "https://github.com/kaiserkiwi/model-settings",
"license": "MIT",
"authors": [
{
"name": "Marco Kaiser",
"email": "marco@kaiser.kiwi"
}
],
"require": {
"php": "^8.2",
"illuminate/database": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0"
},
"require-dev": {
"hyperlinkgroup/pint": "^1.27",
"orchestra/testbench": "^9.0|^10.0|^11.0",
"pestphp/pest": "^4.7"
},
"autoload-dev": {
"psr-4": {
"Kaiserkiwi\\ModelSettings\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/pest"
},
"extra": {
"laravel": {
"providers": [
"Kaiserkiwi\\ModelSettings\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Kaiserkiwi\\ModelSettings\\": "src/"
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
Loading
Loading