2017 © Pedro Peláez
 

library laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

image

cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  • Friday, February 20, 2015
  • by cmarfil
  • Repository
  • 1 Watchers
  • 6 Stars
  • 265 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

laravel-multiuser-json-settings

Simple user settings facade for Laravel 4. Settings are stored as JSON in a single database column, so you can easily add it to an existing table (users for example)., (*1)

Installation

  1. Begin by installing this package through Composer. Edit your project's composer.json file to require cmarfil/laravel-multiuser-json-settings. "require": { "cmarfil/laravel-multiuser-json-settings": "~1.1" }
  2. Add 'Cmarfil\LaravelMultiUserJsonSettings\ServiceProvider' to providers in app/config/app.php., (*2)

    'providers' => array(
    // ...
    'Cmarfil\LaravelMultiUserJsonSettings\ServiceProvider',
    ),
    
  3. Add 'Setting' => 'Cmarfil\LaravelMultiUserJsonSettings\Facade' to aliases in app/config/app.php., (*3)

    'aliases' => array(
    // ...
    'Setting' => 'Cmarfil\LaravelMultiUserJsonSettings\Facade',
    ),
    
  4. Run php artisan config:publish cmarfil/laravel-multiuser-json-settings to publish the config file., (*4)

  5. Modify the published configuration file located at app/config/packages/cmarfil/laravel-multiuser-json-settings/config.php to your liking.
  6. Create a varchar (string) column in a table on your database to match the config file in step 5. Alternatively, use the Laravel migration included in this package to automatically create a settings column in the users table: php artisan migrate --package=cmarfil/laravel-multiuser-json-settings.

Configuration

Pop open app/config/packages/cmarfil/laravel-multiuser-json-settings/config.php to adjust package configuration. If this file doesn't exist, run php artisan config:publish cmarfil/laravel-multiuser-json-settings to create the default configuration file., (*5)

return array(
    'table' => 'users',
    'column' => 'settings',
    'constraint_key' => 'id',
    'default_constraint_value' => (Auth::check() ? Auth::id() : null)
    'custom_constraint' => false, //'id = ' . (Auth::check() ? Auth::id() : null),
);

Table

Specify the table on your database that you want to use., (*6)

Column

Specify the column in the above table that you want to store the settings JSON data in., (*7)

Constraint key

Specify the column constraint - this is used to differentiate between different users, objects or models ( normally id )., (*8)

Default constraint value

Specify the default constraint value - If you do not specify one, default configuration is obtained, in this case the user logged., (*9)

Custom constraint

Specify a where clause for each query - Caution: Leave blank if your want to set or get different rows on same runtime, use constraint_key and default_constraint_value, (*10)

Usage

Use the Setting facade (Setting::) to access the functions in this package., (*11)

Set

Setting::set('key', 'value', $constraint_value);

Use set to change the value of a setting. If the setting does not exist, it will be created automatically. You can set multiple keys at once by passing an associative (key=>value) array to the first parameter. If you do not pass constraint_value the value used by default is default_constraint_value, (*12)

Get

Setting::get('key', 'default', $constraint_value);

Use get to retrieve the value of a setting. The second parameter is optional and can be used to specify a default value if the setting does not exist (the default default value is null). If you do not pass constraint_value the value used by default is default_constraint_value, (*13)

Forget

Setting::forget('key', $constraint_value);

Unset or delete a setting by calling forget. If you do not pass constraint_value the value used by default is default_constraint_value, (*14)

Has

Setting::has('key', $constraint_value);

Check for the existence of a setting, returned as a boolean. If you do not pass constraint_value the value used by default is default_constraint_value, (*15)

All

Setting::all($constraint_value);

Retrieve all settings as an associative array (key=>value). If you do not pass constraint_value the value used by default is default_constraint_value, (*16)

Save

Setting::save($constraint_value);

Save all changes back to the database. This will need to be called after making changes; it is not automatic. If you do not pass constraint_value the value used by default is default_constraint_value, (*17)

Load

Setting::load($constraint_value);

Reload settings from the database. This is called automatically if settings have not been loaded before being accessed or mutated. If you do not pass constraint_value the value used by default is default_constraint_value, (*18)

Example

With default configuration:, (*19)

return array(
    'table' => 'users',
    'column' => 'settings',
    'constraint_key' => 'id',
    'default_constraint_value' => (Auth::check() ? Auth::id() : null)
    'custom_constraint' => false, //'id = ' . (Auth::check() ? Auth::id() : null),
);

The following set and returns the user logged setting "email_notification", (*20)

//Set email_notifications setting to false
Setting::set('email_notifications', false);

//Save config
Setting::save();

//Save email_notifications
return Setting::get('email_notifications');

The following set and returns the setting "email_notification" for user with id 23, (*21)

//Set email_notifications setting to false
Setting::set('email_notifications', false, 23);

//Save config
Setting::save(23);

//Save email_notifications
return Setting::get('email_notifications', true, 23);

Finally

Contributing

Feel free to create a fork and submit a pull request if you would like to contribute., (*22)

Bug reports

Raise an issue on GitHub if you notice something broken., (*23)

Credits

Fork of https://github.com/Grimthorr/laravel-user-settings. Based loosely on https://github.com/anlutro/laravel-settings., (*24)

The Versions

20/02 2015

dev-master

9999999-dev https://github.com/cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  Sources   Download

MIT

The Requires

 

laravel user settings json

20/02 2015

v1.1.3

1.1.3.0 https://github.com/cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  Sources   Download

MIT

The Requires

 

laravel user settings json

17/02 2015

1.1.2

1.1.2.0 https://github.com/cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  Sources   Download

MIT

The Requires

 

laravel user settings json

17/02 2015

1.1.1

1.1.1.0 https://github.com/cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  Sources   Download

MIT

The Requires

 

laravel user settings json

17/02 2015

1.1.0

1.1.0.0 https://github.com/cmarfil/laravel-multiuser-json-settings

Simple user json settings facade for Laravel 4.

  Sources   Download

MIT

The Requires

 

laravel user settings json

21/01 2015
21/01 2015
21/01 2015