codetech / laravel-model-settings
A Laravel package that allows you to assign settings to your models.
Requires
- php: ^7.2
- laravel/framework: ~6.0
This package is auto-updated.
Last update: 2025-05-09 00:30:07 UTC
README
A Laravel package that allows you to assign settings to your models.
Installation & setup
Add the package to your Laravel app using composer
composer require codetech/laravel-model-settings
For changing migrations and configurations, you will need to publish both files by running the following Artisan command:
php artisan vendor:publish --provider="CodeTech\ModelSettings\Providers\ModelSettingsServiceProvider"
Service Provider
Register the package's service provider in config/app.php. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
'providers' => [
...
Codetech\ModelSettings\Providers\ModelSettingsServiceProvider::class,
...
];
Migrations
Execute the next Artisan command to run the migrations.
php artisan migrate
Usage
Use the trait in your models.
use CodeTech\ModelSettings\Traits\HasSettings;
class Theme extends Model
{
use HasSettings;
...
Retrieve model settings
Querying the database
// Get all settings
$settings = $theme->settings;
// Get settings from a specific scope
$scopedSettings = $theme->settings()->ofScope('colors')->get();
Using the config helper
If you have load_into_memory enabled, you can access the settings with the config() helper.
config('theme.colors.primary');
License
codetech/laravel-model-settings is open-sourced software licensed under the MIT license.
About CodeTech
CodeTech is a web development agency based on Matosinhos, Portugal. Oh, and we LOVE Laravel!