Download the PHP package npabisz/laravel-settings without Composer
On this page you can find all versions of the php package npabisz/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-settings
Settings for Laravel
Basic settings for Laravel 9+. Can be either global or morphed to models.
Requirements
- PHP >= 8.1
- Laravel >= 9.0
Installation
Then publish vendor resources and migration
Finally, you should run migration
Basic usage
Example of User
model which uses HasSettings
trait is simple as that:
You can use it with enums
You are not limited to User
model, this works on every model:
There are also different ways and scopes to access:
Scoping to models
Using global scopes
It easier to use global scope for models that won't change during request, eg. logged in user. Which is globally scoped by default, but here is example how to do it manually, eg. you need to persist scope in command.
Settings definitions
Every setting has to have definition. This way it is always of the same type and can have default values. Settings definitions are declared under static method getSettingsDefinitions
.
Remember
Global settings are defined on
Setting
model.
Instead of storing each field of address in separate setting. You can use class which will be then casted to json.
Example of using enums
Example of nullable
setting
Models
If you want to have settings on model you need to use HasSettings
trait and declare some settings definitions.
Now you can get their settings.
License
npabisz/laravel-settings
is released under the MIT License. See the bundled LICENSE for details.
All versions of laravel-settings with dependencies
ext-json Version *
illuminate/contracts Version ^9.0|^10.0|^11.0
illuminate/database Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0