alagaccia/laravel-settings

A Laravel package for managing application settings with a configurable database table

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/alagaccia/laravel-settings

v1.5 2025-12-12 21:06 UTC

This package is auto-updated.

Last update: 2025-12-12 21:07:06 UTC


README

A Laravel package for managing application settings with a configurable database table.

Installation

Install the package via Composer:

composer require alagaccia/laravel-settings

The service provider will be automatically registered.

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=laravel-settings-config

This will create a config/laravel-settings.php file where you can customize the table name:

return [
    'table_name' => env('SETTINGS_TABLE_NAME', 'settings'),
];

Migration

Publish the migration file:

php artisan vendor:publish --tag=laravel-settings-migrations

Then run the migration:

php artisan migrate

This will create a table (default name: settings) with the following structure:

  • id - Auto-increment bigint primary key
  • category - String(255) with index
  • label - String(255)
  • code - String(255) with unique index
  • value - Long text
  • created_at - Timestamp
  • updated_at - Timestamp

Usage

Using the Model

use Alagaccia\LaravelSettings\Models\Setting;

// Create a setting
Setting::create([
    'category' => 'general',
    'label' => 'Site Name',
    'code' => 'site_name',
    'value' => 'My Awesome Site'
]);

// Get a setting by code
$siteName = Setting::getByCode('site_name');

// Get a setting with a default value
$theme = Setting::getByCode('theme', 'default');

// Set or update a setting
Setting::setByCode('site_name', 'New Site Name', 'general', 'Site Name');

// Get all settings in a category
$generalSettings = Setting::getByCategory('general');

Using Helper Functions

The package provides convenient global helper functions:

// Get a setting value
$siteName = getSetting('site_name');

// Get with default value
$theme = getSetting('theme', 'light');

// Set a setting
setSetting('site_name', 'New Site Name', 'general', 'Site Name');

Customizing the Table Name

You can customize the table name in the config file or via environment variable:

SETTINGS_TABLE_NAME=app_settings

License

MIT