digitalion/laravel-simple-user-settings

A simple method for managing user settings

1.0.0 2023-02-03 00:25 UTC

This package is auto-updated.

Last update: 2024-05-04 21:15:56 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.