Persistent settings package for Laravel 5.

Related tags

Database settings
Overview

Package is looking for maintainers Please contact me if interested.

Persistent Settings for Laravel 5

Build Status


Persistent settings package for Laravel 5.


  • Driver support
  • Cache settings via laravel cache
  • Encrypt / Decrypt setting values
  • Fire events after action
  • Override config values
  • Helper function
  • Settings by context
  • Serialize values

Installation

Require this package in your composer.json:

"require": {
  "edvinaskrucas/settings": "2.0.0"
}

Version matrix

Laravel Version Package version
>=5.0, <=5.1 >= 1.0.0, <= 2.0.0
5.2 >= 2.0.0

Registering to use it with laravel

Add following lines to app/config/app.php

ServiceProvider array

Krucas\Settings\Providers\SettingsServiceProvider::class,

Alias array

'Settings' => Krucas\Settings\Facades\Settings::class

Publishing config file

If you want to edit default config file, just publish it to your app folder.

php artisan vendor:publish --provider="Krucas\Settings\Providers\SettingsServiceProvider" --tag="config"

Usage

Configuration

Package comes with several configuration options.

Setting Description
default Setting repository driver.
cache Enable or disable setting cache.
encryption Enable or disable setting value encryption.
events Enable or disable event firing.
repositories Config of all repositories which can be used.
key_generator Key generator class.
context_serializer Context serializer class.
value_serializer Value serializer class.
override Allows you to override values in Laravel config array.

Creating table for database driver

To use database driver you have to create table in your database. Package provides default table migration, to create it you need to execute artisan command:

$ php artisan settings:table

Methods

Set value

Set setting value.

Settings::set($key, $value = null);

Get value

Get setting value, default value is returned when no value found.

Settings::get($key, $default = null);

Check value

Determine if setting exists.

Settings::has($key);

Forget value

Forget setting value from repository.

Settings::forget($key);

Set context

Setting values may be used in certain context. Context can be set using method context().

Settings::context(new Context(['user' => 1]));

Context is reset after call of one these methods set, get, has, forget. Example how to use settings for different contexts.

$userContext1 = new Context(['user' => 1]);
$userContext2 = new Context(['user' => 2]);
Settings::context($userContext1)->set('key', 'value1');
Settings::context($userContext2)->set('key', 'value2');

// retrieve settings
$userValue1 = Settings::context($userContext1)->get('key'); // value1
$userValue2 = Settings::context($userContext2)->get('key'); // value2

Helpers

Settings service instance

Resolve settings service instance.

settings();

Set value

Set setting value.

settings([$key => $value]);

Set setting value for a context.

settings([$key => $value], new Context(['user' => 1]));

Get value

Get setting value, default value is returned when no value found.

settings($key, $default = null);

Getting value for a context.

settings($key, $default, new Context(['user' => 1]));

Events

Events gets fired if this is not disabled via config (enabled by default).

settings.checking: $key

Fired before checking if value is present in repository.

Parameter Type Parameter description
$key string Setting key.
$context null or Context Setting context.

settings.has: $key

Fired after checking if value is present in repository.

Parameter Type Parameter description
$key string Setting key.
$status bool If setting exists true is passed, otherwise false
$context null or Context Setting context.

settings.getting: $key

Fired before retrieving value from repository.

Parameter Type Parameter description
$key string Setting key.
$default mixed Default setting value.
$context null or Context Setting context.

settings.get: $key

Fired after retrieving value from repository.

Parameter Type Parameter description
$key string Setting key.
$value mixed Retrieved setting value.
$default mixed Default setting value.
$context null or Context Setting context.

settings.setting: $key

Fired before setting value to repository.

Parameter Type Parameter description
$key string Setting key.
$value mixed Setting value to be set.
$context null or Context Setting context.

settings.set: $key

Fired after setting value to repository.

Parameter Type Parameter description
$key string Setting key.
$value mixed Setting value to be set.
$context null or Context Setting context.

settings.forgetting: $key

Fired before forgetting value.

Parameter Type Parameter description
$key string Setting key.
$context null or Context Setting context.

settings.forget: $key

Fired after forgetting value.

Parameter Type Parameter description
$key string Setting key.
$context null or Context Setting context.
Comments
  • User-specific settings

    User-specific settings

    Hi

    Thanks for your package. I'm glad we share the same philosophy regarding the already existing persistent settings packages.

    How about a new feature to allow user-specific settings? Shouldn't be that hard to implement: a new fluent method forUser( ID or Model ) that prepends the requested $key with some string + id..

    Of course this behavior can be self-coded in terms of a service class, but in my humble opinion it would also fit great in this package..

    opened by Propaganistas 7
  • Documentation: How to create a Repository Driver

    Documentation: How to create a Repository Driver

    I'd like to create a custom Repository Driver for my app, but I'm not quite getting it all put together.

    Can you give some instructions on what needs to be done to add a custom driver?

    opened by murrant 3
  • Support for Laravel 6.

    Support for Laravel 6.

    I made the package working for Laravel 6.X. Minimum PHP required is same as Laravel, 7.2

    Also all tests were upgraded to work with newest PHPUnit.

    All tests are passing

    Please review and potentially approve into new version - 3.x?

    opened by juouy 2
  • Perhaps last update to 6.0 LTS?

    Perhaps last update to 6.0 LTS?

    Thank you for creating one of best packages for user settings (one of few with caching). Pitty it's not maintained.

    Perhaps you could make last one update for 6.0LTS? That should be enough for 3 years... of support. Currently it doesnt even install using composer as dependencies are hardcoded.

    opened by juouy 1
  • unserialize error + disabled cache

    unserialize error + disabled cache

    I use this config:

    return [
        'default' => env('SETTINGS_DRIVER', 'database'),
        'cache' => true,
        'encryption' => false,
        'events' => true,
        'repositories' => [
            'database' => [
                'driver' => 'database',
                'connection' => env('DB_CONNECTION', 'mysql'),
                'table' => 'settings',
            ],
        ],
        'key_generator' => \Krucas\Settings\KeyGenerators\KeyGenerator::class,
        'context_serializer' => \Krucas\Settings\ContextSerializers\ContextSerializer::class,
        'value_serializer' => \Krucas\Settings\ValueSerializers\ValueSerializer::class,
        'override' => [],
    ];
    

    And Laravel Framework version 5.3.23. Then I set 'cache' => false - application crushes with message:

    ErrorException in /home/user/php/my_app/vendor/edvinaskrucas/settings/src/Krucas/Settings/ValueSerializers/ValueSerializer.php line 28: unserialize(): Error at offset 0 of 3 bytes (View: /home/user/php/my_app/resources/views/pages/settings/index.blade.php)

    Database is clear (after migrate:refresh), files cache is cleared. And if I change 'cache' => true- all works fine. Is it normal?

    opened by tarampampam 1
  • Laravel version >=5.0, <=5.1 with <= 2.0.0 or with < 2.0.0

    Laravel version >=5.0, <=5.1 with <= 2.0.0 or with < 2.0.0

    Hello @edvinaskrucas , this is only a question... In your readme you say: Laravel version >=5.0, <=5.1 Package version >= 1.0.0, <= 2.0.0 Is correct <= 2.0.0 for Laravel 5.1 or is correct < 2.0.0 ?

    Thanks

    opened by Uebix 1
  • Serialize to support complex values

    Serialize to support complex values

    e.g. arrays or objects.

    My use case: an array of locales to override Laravel Localization's supportedLocales config.

    Note that the cache needs to be cleared in order to see the effects of this.

    opened by Propaganistas 1
  • .env issue

    .env issue

    No1 local.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.' No2 local.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.'

    Once in a while i get these error one after another for some reason the .env is not being picked up and the default SomeRandomString obviously makes it all fails.

    this also happens with the database settings

    Once i change the app and database file no more issues

    opened by kiwina 1
  • Laravel 5.2 moved Composer class

    Laravel 5.2 moved Composer class

    See http://laravel.com/docs/5.2/upgrade

    Illuminate\Foundation\Composer is moved to Illuminate\Support\Composer

    Currently this results in an error in SettingsTableCommand when interacting with artisan.

    opened by Propaganistas 0
  • Method Krucas\Settings\Console\SettingsTableCommand::handle() does not exist

    Method Krucas\Settings\Console\SettingsTableCommand::handle() does not exist

    Hi I'm trying to run this command: php artisan settings:table

    And i'm getting this error in the console : ReflectionException : Method Krucas\Settings\Console\SettingsTableCommand::handle() does not exist laravel : 5.7

    Any idea?

    opened by AMAFsoft 1
  • settings method call fails

    settings method call fails

    opened by CycloneAxe 0
Owner
Edvinas Kručas
Edvinas Kručas
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.

Laravel showsql A Laravel package to output a specific sql to your favourite debugging tool, your browser or your log file. Use case You often want to

Dieter Coopman 196 Dec 28, 2022
A package to backup your Laravel app

A modern backup solution for Laravel apps This Laravel package creates a backup of your application. The backup is a zip file that contains all files

Spatie 5.1k Jan 1, 2023
[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

Orchestra Platform 580 Dec 5, 2022
A mysql database backup package for laravel

Laravel Database Backup Package This package will take backup your mysql database automatically via cron job. Installing laravel-backup The recommende

Mahedi Hasan Durjoy 20 Jun 23, 2021
Eloquent Filter is a package for filter data of models by the query strings. Easy to use and fully dynamic.

Eloquent Filter Eloquent Filter adds custom filters to your Eloquent Models in Laravel. It's easy to use and fully dynamic. Table of Content Introduct

Mehdi Fathi 327 Dec 28, 2022
This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FTP, SFTP, and Rackspace Cloud

Database Backup Manager This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FT

Backup Manager 1.6k Dec 23, 2022
A package for using Google Datastore as a database driver

Laravel Eloquent for Google Datastore A package for using Google Datastore as a database driver. By using this package, you can use query builder and

A1 Comms Ltd 3 Apr 26, 2022
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. ?? Supporting If you are usin

Renoki Co. 9 Nov 15, 2022
This project is about import CSV to Laravel with Laravel Excel library.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Abraham Víctor Zaragoza Rodríguez 1 Nov 20, 2021
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.

Baum Baum is an implementation of the Nested Set pattern for Laravel 5's Eloquent ORM. For Laravel 4.2.x compatibility, check the 1.0.x branch branch

Estanislau Trepat 2.2k Jan 3, 2023
Driver to seamlessly integrate the Backup Manager into Laravel applications.

Laravel Driver for the Database Backup Manager This package pulls in the framework agnostic Backup Manager and provides seamless integration with Lara

Backup Manager 636 Dec 30, 2022
Effective tree structures in Laravel 4-5

This is a Laravel 4-8 package for working with trees in relational databases. Laravel 5.7, 5.8, 6.0, 7.0, 8.0 is supported since v5 Laravel 5.5, 5.6 i

Alexander Kalnoy 3.3k Jan 6, 2023
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Yan Ivanov 441 Dec 11, 2022
A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Eloquence Eloquence is a package to extend Laravel's base Eloquent models and functionality. It provides a number of utilities and classes to work wit

Kirk Bushell 470 Dec 8, 2022
Laravel Inverse Seed Generator

Inverse seed generator (iSeed) is a Laravel package that provides a method to generate a new seed file based on data from the existing database table.

Orange Hill Development 2.5k Dec 29, 2022
Oracle DB driver for Laravel 4|5|6|7|8 via OCI8

Oracle DB driver for Laravel 4|5|6|7|8 via OCI8 Laravel-OCI8 Laravel-OCI8 is an Oracle Database Driver package for Laravel. Laravel-OCI8 is an extensi

Arjay Angeles 751 Jan 6, 2023
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Laravel Doctrine ORM A drop-in Doctrine ORM 2 implementation for Laravel 5+ $scientist = new Scientist( 'Albert', 'Einstein' ); $scientist->a

Laravel Doctrine 777 Dec 17, 2022
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Jens Segers 6.3k Jan 5, 2023