Download the PHP package cmarfil/laravel-multiuser-json-settings without Composer
On this page you can find all versions of the php package cmarfil/laravel-multiuser-json-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-multiuser-json-settings
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).
Installation
-
Begin by installing this package through Composer. Edit your project's composer.json file to require cmarfil/laravel-multiuser-json-settings.
-
Add
'Cmarfil\LaravelMultiUserJsonSettings\ServiceProvider'
toproviders
inapp/config/app.php
. -
Add
'Setting' => 'Cmarfil\LaravelMultiUserJsonSettings\Facade'
toaliases
inapp/config/app.php
. - Run
php artisan config:publish cmarfil/laravel-multiuser-json-settings
to publish the config file. - Modify the published configuration file located at
app/config/packages/cmarfil/laravel-multiuser-json-settings/config.php
to your liking. - 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 theusers
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.
Table
Specify the table on your database that you want to use.
Column
Specify the column in the above table that you want to store the settings JSON data in.
Constraint key
Specify the column constraint - this is used to differentiate between different users, objects or models ( normally id ).
Default constraint value
Specify the default constraint value - If you do not specify one, default configuration is obtained, in this case the user logged.
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
Usage
Use the Setting facade (Setting::
) to access the functions in this package.
Set
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
Get
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
Forget
Unset or delete a setting by calling forget
.
If you do not pass constraint_value the value used by default is default_constraint_value
Has
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
All
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
Save
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
Load
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
Example
With default configuration:
The following set and returns the user logged setting "email_notification"
The following set and returns the setting "email_notification" for user with id 23
Finally
Contributing
Feel free to create a fork and submit a pull request if you would like to contribute.
Bug reports
Raise an issue on GitHub if you notice something broken.
Credits
Fork of https://github.com/Grimthorr/laravel-user-settings. Based loosely on https://github.com/anlutro/laravel-settings.
All versions of laravel-multiuser-json-settings with dependencies
illuminate/support Version 4.*
illuminate/config Version 4.*
illuminate/database Version 4.*