Download the PHP package smartisan/laravel-settings without Composer
On this page you can find all versions of the php package smartisan/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smartisan/laravel-settings
More information about smartisan/laravel-settings
Files in smartisan/laravel-settings
Package laravel-settings
Short Description App & Models Settings for Laravel
License MIT
Homepage https://github.com/itsmohd/settings
Informations about the package laravel-settings
App & Models Settings for Laravel
This package allows you to store application wide and model specific Laravel settings. Settings values are type-cast and stored properly. You can also define your own casts and store repository.
Installation
Install the package via composer:
Publish the config file with:
Publish the migration file with:
And finally run the migration with:
Usage
The package provides various APIs to access the settings manager. You can access it with Settings facade, settings() helper method and via HasSettings trait on your models.
Store Settings
You can set single entry, or multiple entries of settings. The values of objects will be cast according to the rules defined in settings.php config file.
-
One Entry
- Multiple Entries
You can set multiple settings entries by passing an associative array of keys and values. Casts will be applied on all the payload, even on nested arrays.
- Specify Settings Group
It's possible to categorize your settings into groups by calling group method.
- Model Specific Settings
It's also possible to set settings for a specific model by calling for method
- Mixing Filters
You can mix all filters together like this:
Retrieve Settings
You can retrieve one or multiple entries and specify the default value if not exist.
-
One Entry
- Multiple Entries
If the entry key does not exist, the default value will be placed instead
- All Entries
If you want to retrieve all entries, you simply call all method. You can also specify the model or group. Also to excempt some specific keys.
Note: Remember that retrieving all entries without specifying the group or model, will retrieve all entries that has no group or model set. You can consider these as (global app settings).
Forget Entry
You can remove entries by calling forget method.
Determine Existance
You can determine whether the given settings entry key exists or not
Helper Method
The package also ships with a settings helper method, you can use it instead of using Settings Facade
HasSettings Trait
You can use HasSettings trait on your Eloquent models as well
-
First prepare your model
- Now you can call settings() method on that model. This is equivelant to
Custom Repositories
If you don't want to use the database repository, you can easily create your own settings repository. To do that
-
Create a class of your repository that implements Repository interface and implement the following methods
-
In settings configuration file, add your own repository config to repositories attribute
- Change the default repository in settings config file to your own repository implementation
Custom Casts
The package allows you to easily create your own casting rules of any object type.
- Create your own cast class that implements Castable interface.
Note: The set method is called when the value of the entries is being stored to the repository, and the get method is called when the value is being retrieved from the repository.
- Add the casts to the array of casts in settings config file
Note: If you want to pass a parameter to your cast, you can set an object of the cast instead of cast class name
Settings Cache
You can easily enable or disable caching settings in settings.php config file. You can also specify which caching store to use
Testing
To run the package's tests, simply call the following command
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Mohammed Isa
- All Contributors
Alternatives
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-settings with dependencies
ext-json Version *
illuminate/database Version ^10.0
illuminate/support Version ^10.0