Skip to content

Write default value to the database on getting the setting#7

Merged
kaiserkiwi merged 8 commits into
mainfrom
6-write-default-value-to-the-database-on-getting-the-setting
May 12, 2026
Merged

Write default value to the database on getting the setting#7
kaiserkiwi merged 8 commits into
mainfrom
6-write-default-value-to-the-database-on-getting-the-setting

Conversation

@kaiserkiwi

@kaiserkiwi kaiserkiwi commented May 12, 2026

Copy link
Copy Markdown
Owner

Closes #6

This Pull Request makes the Plugin ready for Laravel 13, adds the option to write default values to the database (Disabled by default) and adds tests to the Package.

Features

  • Laravel 13 Support
  • New save_default config to enable oder disabling saving the default value to the Database if it isn't there yet

Fixes

  • Update null check for setting value and add caching tests for falsy values
  • Handle concurrent insert race in setSetting method

Tests

I finally added tests to the package so I don't have to guess if everything works as expected. I also added GitHub Actions.

Info: I also fixed the minimum required PHP version as the illuminate packages require PHP 8.2+
…ing settings

- For better readability I also move the now more complex logic to a fetchSetting method
- Add missing trailing commas in multiple places

Closes: #6
@kaiserkiwi kaiserkiwi requested a review from Copilot May 12, 2026 07:11
@kaiserkiwi kaiserkiwi self-assigned this May 12, 2026
@kaiserkiwi kaiserkiwi added the enhancement New feature or request label May 12, 2026
@kaiserkiwi kaiserkiwi linked an issue May 12, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the package for Laravel 13 compatibility and introduces an optional save_default configuration that can persist default values to the database when a setting is first read and missing. It also adds a Pest-based test suite and GitHub Actions CI to validate behavior across multiple PHP/Laravel versions.

Changes:

  • Add model_settings.save_default (and MODEL_SETTINGS_SAVE_DEFAULT) and implement “persist default on read” in HasSettings::getSetting().
  • Add Pest + Orchestra Testbench test setup and feature tests for the settings trait.
  • Add CI workflow to run tests across PHP 8.2–8.4 and Laravel 11–13.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/HasSettings.php Implements optional persistence of default values during getSetting() and refactors DB fetch logic.
config/model_settings.php Adds save_default config key backed by env var.
README.md Documents the new env/config option and behavior.
tests/TestCase.php Adds Testbench base test case and in-memory SQLite migrations.
tests/Pest.php Sets up Pest to use the package TestCase.
tests/Models/TestUser.php Adds a minimal Eloquent model for trait testing.
tests/Feature/HasSettingsTest.php Adds feature tests for HasSettings behavior (including save_default).
.github/workflows/tests.yml Adds CI matrix to run tests on supported PHP/Laravel versions.
phpunit.xml Adds PHPUnit configuration to support Pest runs and coverage source inclusion.
composer.json Updates supported PHP/Laravel versions and adds test tooling dependencies/scripts.
.gitignore Ignores PHPUnit result cache file.
.editorconfig Extends editor defaults for JSON/YAML indentation and related settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread composer.json Outdated
Comment thread src/HasSettings.php Outdated
Comment thread src/HasSettings.php
Comment thread src/HasSettings.php
@kaiserkiwi kaiserkiwi force-pushed the 6-write-default-value-to-the-database-on-getting-the-setting branch from 1e83747 to 7770dee Compare May 12, 2026 07:15
@kaiserkiwi kaiserkiwi force-pushed the 6-write-default-value-to-the-database-on-getting-the-setting branch from 7770dee to 0261728 Compare May 12, 2026 07:43
@kaiserkiwi

Copy link
Copy Markdown
Owner Author

Tested it locally in my own projects. I didn't find any oddities.

@kaiserkiwi kaiserkiwi merged commit 6287331 into main May 12, 2026
6 checks passed
@kaiserkiwi kaiserkiwi deleted the 6-write-default-value-to-the-database-on-getting-the-setting branch May 12, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write default value to the database on getting the setting

2 participants