A Laravel package that allows you to assign settings to your models.
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"
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,
...
];
Execute the next Artisan command to run the migrations.
php artisan migrate
Use the trait in your models.
use CodeTech\ModelSettings\Traits\HasSettings;
class Theme extends Model
{
use HasSettings;
...
// Get all settings
$settings = $theme->settings;
// Get settings from a specific scope
$scopedSettings = $theme->settings()->ofScope('colors')->get();
If you have load_into_memory enabled, you can access the settings with the config() helper.
config('theme.colors.primary');
codetech/laravel-model-settings is open-sourced software licensed under the MIT license.
CodeTech is a web development agency based on Matosinhos, Portugal. Oh, and we LOVE Laravel!