digitalion / laravel-simple-user-settings
A simple method for managing user settings
Requires
- php: ^8.0
- illuminate/contracts: ^8.0|^9.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-04 22:33:54 UTC
README
This is a simple way to manage user settings. The settings will be based on the configuration file and then stored within a json field in the users table.
Installation
You can install the package via composer:
composer require digitalion/laravel-simple-user-settings
Once installed you can publish the configuration file with:
php artisan vendor:publish --tag="laravel-simple-user-settings-config"
The configuration file will be empty, but you can fill it with any settings your app offers.
Right after that you will need to add the settings
field to the users
table.
php artisan migrate
Optionally, you can publish the migration to make any changes with:
php artisan vendor:publish --tag="laravel-simple-user-settings-migrations"
Usage
The package will offer you the settings
helper with which you can directly access user settings.
Read all settings
With the settings()
command you will get the array of all settings. If the user has no saved settings, all the basic values will be returned.
Reading a value
To read a given settings value you will have to use the settings('key')
command.
To get a nested value, use the dot as a separator. For example: settings('key1.key2.key3')
.
Set a value
The values can be set with the command: settings('key', 'value')
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.