rayhan2001/laravel-settings-manager

A simple and reusable Laravel package for managing application settings (general, email, social, payment, etc).

v0.0.1 2025-08-24 11:36 UTC

This package is not auto-updated.

Last update: 2025-09-08 10:03:46 UTC


README

A simple and reusable Laravel package for managing application settings (general, email, social, payment, etc).

Features

  • Easy to use settings management system
  • Built-in UI for managing settings (optional)
  • Caching for improved performance
  • Configurable form sections and fields
  • Support for various field types (text, email, url, select, password, etc)
  • Ready-to-use migrations, config, and views

Installation

Step 1: Add Package to Autoloader

Add the package to your main composer.json file's autoload section:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/",
        "Rayhan\\Settings\\": "laravel-settings-manager/src/"
    }
}

Then run:

composer dump-autoload

Step 2: Register Service Provider

Add the service provider to your bootstrap/providers.php file:

return [
    App\Providers\AppServiceProvider::class,
    Rayhan\Settings\SettingsServiceProvider::class, // Add this line
];

Step 3: Publish Assets

Publish the package assets using one of the following commands:

Publish All Assets

php artisan vendor:publish --provider="Rayhan\Settings\SettingsServiceProvider"

Publish Only Config

php artisan vendor:publish --provider="Rayhan\Settings\SettingsServiceProvider" --tag=config

Publish Only Migrations

php artisan vendor:publish --provider="Rayhan\Settings\SettingsServiceProvider" --tag=migrations

Publish Only Views

php artisan vendor:publish --provider="Rayhan\Settings\SettingsServiceProvider" --tag=views

Step 4: Run Migrations

Run the migrations to create the settings table:

php artisan migrate

Configuration

The configuration file is published to config/settings.php. You can customize the following options:

UI Settings

  • ui.enabled: Enable/disable the built-in UI (default: true)
  • ui.middleware: Middleware for UI routes (default: ['web', 'auth'])
  • ui.prefix: Route prefix for UI (default: 'admin/settings')
  • ui.route_name_prefix: Route name prefix (default: 'settings.')

Cache Settings

  • cache.enabled: Enable/disable caching (default: true)
  • cache.key: Cache key (default: 'rayhan.settings.all')
  • cache.ttl: Cache time-to-live in seconds (default: 3600)

Form Sections

The package comes with pre-configured form sections:

  • General settings (site name, tagline, URL)
  • Email settings (SMTP configuration)
  • Social media links
  • Payment gateway settings (Stripe, PayPal, SSLCommerz)

Usage

Using the Settings Facade

// Get a setting value
$value = Settings::get('site_name');

// Set a setting value
Settings::set('site_name', 'My Awesome Site');

// Get all settings
$allSettings = Settings::all();

// Check if a setting exists
if (Settings::has('site_name')) {
    // Do something
}

Using the Settings Helper

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

// Set a setting value
settings(['site_name' => 'My Awesome Site']);

// Get all settings
$allSettings = settings();

Using the Settings Service

use Rayhan\Settings\Services\SettingsManager;

class YourController extends Controller
{
    public function index(SettingsManager $settings)
    {
        $siteName = $settings->get('site_name');
        // ...
    }
}

Available Field Types

The package supports various field types for the built-in UI:

  • text: Text input
  • email: Email input
  • url: URL input
  • number: Number input
  • select: Dropdown select
  • password: Password input
  • textarea: Textarea

Customization

Adding New Sections

You can add new sections by modifying the sections array in config/settings.php:

'sections' => [
    'general' => [
        // ...
    ],
    'custom' => [
        'title' => 'Custom Section',
        'icon' => 'bi-star',
        'fields' => [
            [
                'type' => 'text',
                'label' => 'Custom Field',
                'key' => 'custom_field',
                'placeholder' => 'Enter custom value',
                'rules' => 'nullable|string|max:255',
            ],
        ],
    ],
],

Modifying UI Routes

You can disable the built-in UI by setting ui.enabled to false in the config file, or customize the middleware and route prefix as needed.

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0 or higher

License

The MIT License (MIT). Please see License File for more information.