PHPackages                             salehye/settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. salehye/settings

ActiveLibrary[Localization &amp; i18n](/categories/localization)

salehye/settings
================

A lightweight Laravel settings package with InertiaJS support

1.0.0(1mo ago)00MITPHPPHP ^8.4CI failing

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/salehye/settings)[ Packagist](https://packagist.org/packages/salehye/settings)[ GitHub Sponsors](https://github.com/salehye)[ RSS](/packages/salehye-settings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Salehye Settings Package
========================

[](#salehye-settings-package)

> **A lightweight, flexible Laravel settings package with InertiaJS &amp; Blade support, multilingual capabilities, and database-driven configuration.**

[![Laravel](https://camo.githubusercontent.com/38d07b3a689d56f5b4ee190702d62369188818bf9f407c89389e8fe72b115d4f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/38d07b3a689d56f5b4ee190702d62369188818bf9f407c89389e8fe72b115d4f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)[![PHP](https://camo.githubusercontent.com/42e9da7915dbb5d727afb84ac5e1432293993bbe7c6e20127e01bce96d1520a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342b2d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870)](https://camo.githubusercontent.com/42e9da7915dbb5d727afb84ac5e1432293993bbe7c6e20127e01bce96d1520a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342b2d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870)[![InertiaJS](https://camo.githubusercontent.com/74f0dc58c004a92318c4e6f8ccaf001f6489aacd13b83bed62275a5222f8323c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f496e65727469614a532d322e782d3935353345393f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/74f0dc58c004a92318c4e6f8ccaf001f6489aacd13b83bed62275a5222f8323c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f496e65727469614a532d322e782d3935353345393f7374796c653d666c61742d737175617265)[![Blade](https://camo.githubusercontent.com/0bf65adae9cfef62bb52adeb81996c25426de6f7ac3a96e7344697c8dc46bd67/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f426c6164652d52656164792d4635353033433f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/0bf65adae9cfef62bb52adeb81996c25426de6f7ac3a96e7344697c8dc46bd67/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f426c6164652d52656164792d4635353033433f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/152aa2a37725b9fd554b28ff24d270f6071c67927a63e6d635a55c8e188e20c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/152aa2a37725b9fd554b28ff24d270f6071c67927a63e6d635a55c8e188e20c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e3f7374796c653d666c61742d737175617265)[![Tests](https://camo.githubusercontent.com/9a283f6ec252ea803eea8c415afcd80a5a047148265621c90431882c2f73d095/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616c656879652f73657474696e67732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9a283f6ec252ea803eea8c415afcd80a5a047148265621c90431882c2f73d095/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616c656879652f73657474696e67732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fd6a032f73b75fc228bb8106f7b1c4dba47a1fa48cf06eef47f134cab6eace99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616c656879652f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salehye/settings)[![Total Downloads](https://camo.githubusercontent.com/3a23b0f81fca432a3afed33517eb23324701681d507f63fb7cc11bfea8c454d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616c656879652f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salehye/settings)

✨ Features
----------

[](#-features)

- 🗄️ **Database-Driven** - Store settings in database with `is_public` flag
- 🌐 **Multilingual** - Support for translated labels and content
- ⚡ **Caching** - Built-in caching for optimal performance
- 🎨 **InertiaJS Ready** - Auto-share public settings with frontend
- 🔧 **Flexible** - Works with or without predefined definitions
- 🧪 **Tested** - Comprehensive Pest PHP test suite
- 📦 **SOLID** - Clean architecture following Laravel best practices

📦 Installation
--------------

[](#-installation)

### 1. Require the package

[](#1-require-the-package)

```
composer require salehye/settings
```

### 2. Publish assets

[](#2-publish-assets)

```
# Publish config file
php artisan vendor:publish --provider="Salehye\Settings\SettingsServiceProvider" --tag="settings-config"

# Publish migrations
php artisan vendor:publish --provider="Salehye\Settings\SettingsServiceProvider" --tag="settings-migrations"

# Publish all
php artisan vendor:publish --provider="Salehye\Settings\SettingsServiceProvider"
```

### 3. Run migrations

[](#3-run-migrations)

```
php artisan migrate
```

### 4. Register Middleware (Optional)

[](#4-register-middleware-optional)

Add the middleware to share settings with Inertia automatically:

**Laravel 11.x/12.x** (`bootstrap/app.php`):

```
use Salehye\Settings\Http\Middleware\ShareSettingsMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->web(append: [
            ShareSettingsMiddleware::class,
        ]);
    })
    ->withProviders();
```

🚀 Usage Methods
---------------

[](#-usage-methods)

### Method 1: Helper Functions (Recommended) ⭐

[](#method-1-helper-functions-recommended-)

```
// Get a setting
$siteName = settings('site_name');
$siteName = setting('site_name'); // Alias

// Set a setting
set_setting('site_name', 'My Website');

// Get group
$general = settings_group('general');

// Get public settings
$public = settings_public();

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

// With default value
$timezone = settings('timezone', 'UTC');
```

### Method 2: Facade

[](#method-2-facade)

```
use Salehye\Settings\Facades\Settings;

// Get
$value = Settings::get('site_name');
$value = Settings::get('site_name', 'Default');

// Set
Settings::set('site_name', 'My Website');

// Multiple
$settings = Settings::getMany(['site_name', 'timezone']);
Settings::setMany([
    'site_name' => 'My Site',
    'timezone' => 'Asia/Riyadh',
]);

// Group
$general = Settings::group('general');

// Public
$public = Settings::public();

// All
$all = Settings::all();

// Check
if (Settings::has('site_name')) {
    // ...
}

// Delete
Settings::delete('site_name');

// Cache
Settings::clearCache();
Settings::reload();
```

### Method 3: Magic Methods

[](#method-3-magic-methods)

```
use Salehye\Settings\Facades\Settings;

// Magic getter
$siteName = Settings::$site_name;

// Magic isset
if (isset(Settings::$site_name)) {
    // ...
}

// Invoke as function
$value = Settings('site_name');
$value = Settings('site_name', 'default');
$all = Settings(); // Returns all settings
```

### Method 4: HasSettings Trait (In Controllers)

[](#method-4-hassettings-trait-in-controllers)

```
use Salehye\Settings\Concerns\HasSettings;

class MyController extends Controller
{
    use HasSettings;

    public function index()
    {
        $siteName = $this->getSetting('site_name');
        $this->setSetting('timezone', 'UTC');

        $settings = $this->getSettings(['site_name', 'timezone']);
        $general = $this->getSettingsGroup('general');
        $public = $this->getPublicSettings();
        $all = $this->getAllSettings();

        if ($this->hasSetting('site_name')) {
            // ...
        }

        $this->deleteSetting('old_setting');
        $this->clearSettingsCache();
    }
}
```

### Method 5: Dependency Injection

[](#method-5-dependency-injection)

```
use Salehye\Settings\SettingsManager;
use Salehye\Settings\Contracts\SettingsRepositoryInterface;

class MyService
{
    public function __construct(
        protected SettingsManager $settings,
        // OR
        protected SettingsRepositoryInterface $repository
    ) {}

    public function doSomething(): void
    {
        $value = $this->settings->get('site_name');
        // OR
        $value = $this->repository->get('site_name');
    }
}
```

🎨 Blade Templates Integration
-----------------------------

[](#-blade-templates-integration)

### View Composer (Automatic)

[](#view-composer-automatic)

Public settings are **automatically shared** with all Blade views:

```
{{-- In any Blade template --}}
{{ $settings['site_name'] ?? 'Default' }}

{{-- Access any public setting --}}
{{ $settings['contact_email'] }}
```

### Blade Directives

[](#blade-directives)

```
{{-- Get a setting --}}
@settings('site_name')
@setting('site_name')  {{-- Alias --}}

{{-- Get with default --}}
@settingsOr('timezone', 'UTC')

{{-- Conditional rendering --}}
@ifSettings('maintenance_mode')
    Maintenance Mode Active
@endIfSettings

{{-- Get as JSON --}}

    const keywords = @jsonSettings('seo_keywords');

{{-- Get group settings --}}

    const general = @settingsGroup('general');

```

### Blade Component

[](#blade-component)

```
{{-- Simple usage --}}

{{-- With default --}}

```

### Publish Component Views

[](#publish-component-views)

```
php artisan vendor:publish --tag=settings-views
```

Then customize in `resources/views/vendor/settings/components/setting.blade.php`

📊 Database Schema
-----------------

[](#-database-schema)

```
Schema::create('settings', function (Blueprint $table) {
    $table->id();
    $table->string('key')->unique()->index();
    $table->string('group')->default('general')->index();
    $table->boolean('is_public')->default(false)->index();
    $table->json('value')->nullable();
    $table->timestamps();

    $table->index(['group', 'is_public']);
});
```

🎯 Creating Settings
-------------------

[](#-creating-settings)

### Method 1: Direct Database (Recommended)

[](#method-1-direct-database-recommended)

```
use Salehye\Settings\Models\Setting;

// Simple setting
Setting::create([
    'key' => 'site_name',
    'group' => 'general',
    'is_public' => true,
    'value' => 'My Website',
]);

// JSON setting
Setting::create([
    'key' => 'social_links',
    'group' => 'social',
    'is_public' => true,
    'value' => [
        'twitter' => 'https://twitter.com/mysite',
        'facebook' => 'https://facebook.com/mysite',
    ],
]);

// Boolean setting
Setting::create([
    'key' => 'maintenance_mode',
    'group' => 'system',
    'is_public' => false,
    'value' => false,
]);
```

### Method 2: With Config Definitions

[](#method-2-with-config-definitions)

Add to `config/settings.php`:

```
'definitions' => [
    'site_name' => [
        'type' => 'string',
        'group' => 'general',
        'is_public' => true,
        'default' => 'My Website',
        'rules' => ['nullable', 'string', 'max:255'],
        'translations' => [
            'ar' => 'اسم الموقع',
            'en' => 'Site Name',
        ],
    ],
],
```

🌐 InertiaJS Integration
-----------------------

[](#-inertiajs-integration)

### Auto-Share Public Settings

[](#auto-share-public-settings)

After registering `ShareSettingsMiddleware`, all public settings are automatically shared:

```
// In your Vue/React component
import { usePage } from "@inertiajs/vue3"; // or '@inertiajs/react'

const page = usePage();
const settings = page.props.settings;

console.log(settings.site_name); // Access public settings
```

### Settings Controller

[](#settings-controller)

The package provides a controller for settings management:

```
// routes/web.php
use Salehye\Settings\Http\Controllers\SettingsController;

Route::middleware(['auth'])->group(function () {
    Route::get('/settings', [SettingsController::class, 'index']);
    Route::get('/settings/{group}', [SettingsController::class, 'show']);
    Route::put('/settings', [SettingsController::class, 'update']);
});
```

### Inertia Frontend Example (Vue 3)

[](#inertia-frontend-example-vue-3)

```

import { useForm } from "@inertiajs/vue3";

const form = useForm({
  settings: {
    site_name: "My Website",
    site_description: "",
  },
});

const submit = () => {
  form.put("/settings", {
    onSuccess: () => console.log("Settings updated!"),
  });
};

    Save

```

🔧 Configuration
---------------

[](#-configuration)

### Cache Settings

[](#cache-settings)

```
// config/settings.php
'cache' => [
    'enabled' => true,
    'ttl' => 3600, // 1 hour
    'key' => 'settings_cache',
],
```

### Inertia Settings

[](#inertia-settings)

```
// config/settings.php
'inertia' => [
    'share_public' => true,      // Auto-share public settings
    'key_name' => 'settings',    // Key name in Inertia props
],
```

🧙‍♂️ Advanced Usage
-------------------

[](#‍️-advanced-usage)

### Type Casting

[](#type-casting)

The package automatically handles type casting based on config definitions:

```
// Boolean
Setting::create([
    'key' => 'maintenance_mode',
    'value' => true, // Stored as boolean
]);

// JSON/Array
Setting::create([
    'key' => 'features',
    'value' => ['dark_mode' => true, 'notifications' => false],
]);

// Integer
Setting::create([
    'key' => 'posts_per_page',
    'value' => 10,
]);
```

### Custom Repository

[](#custom-repository)

```
use Salehye\Settings\Contracts\SettingsRepositoryInterface;

class MyService
{
    public function __construct(
        protected SettingsRepositoryInterface $settings
    ) {}

    public function doSomething(): void
    {
        $value = $this->settings->get('my_setting');
    }
}
```

### Clear Cache

[](#clear-cache)

```
// Clear cache after bulk updates
Settings::clearCache();

// Reload from database
Settings::reload();
```

🧪 Testing
---------

[](#-testing)

```
# Run tests
composer test

# Run tests with coverage
composer test:coverage
```

📝 Example: Complete Setup
-------------------------

[](#-example-complete-setup)

### 1. Create Settings Seeder

[](#1-create-settings-seeder)

```
// database/seeders/SettingsSeeder.php
use Salehye\Settings\Models\Setting;

public function run(): void
{
    $settings = [
        ['key' => 'site_name', 'group' => 'general', 'is_public' => true, 'value' => 'My Website'],
        ['key' => 'site_description', 'group' => 'general', 'is_public' => true, 'value' => 'Welcome to my site'],
        ['key' => 'timezone', 'group' => 'general', 'is_public' => false, 'value' => 'Asia/Riyadh'],
        ['key' => 'maintenance_mode', 'group' => 'system', 'is_public' => false, 'value' => false],
        ['key' => 'contact_email', 'group' => 'contact', 'is_public' => true, 'value' => 'info@example.com'],
        ['key' => 'social_twitter', 'group' => 'social', 'is_public' => true, 'value' => ''],
        ['key' => 'social_facebook', 'group' => 'social', 'is_public' => true, 'value' => ''],
    ];

    foreach ($settings as $setting) {
        Setting::firstOrCreate(['key' => $setting['key']], $setting);
    }
}
```

### 2. Run Seeder

[](#2-run-seeder)

```
php artisan db:seed --class=SettingsSeeder
```

### 3. Use in Application

[](#3-use-in-application)

```
// Backend
$siteName = Settings::get('site_name');

// Frontend (Inertia)
const { site_name } = usePage().props.settings;
```

📦 Package Structure
-------------------

[](#-package-structure)

```
salehye/settings/
├── config/
│   └── settings.php
├── database/
│   ├── factories/
│   │   └── SettingFactory.php
│   └── migrations/
│       └── create_settings_table.php
├── src/
│   ├── Contracts/
│   │   └── SettingsRepositoryInterface.php
│   ├── Facades/
│   │   └── Settings.php
│   ├── Http/
│   │   ├── Controllers/
│   │   │   └── SettingsController.php
│   │   └── Middleware/
│   │       └── ShareSettingsMiddleware.php
│   ├── Models/
│   │   └── Setting.php
│   ├── Repositories/
│   │   └── SettingsRepository.php
│   ├── Services/
│   │   └── SettingsService.php
│   ├── SettingsManager.php
│   └── SettingsServiceProvider.php
└── tests/

```

🧪 Testing
---------

[](#-testing-1)

```
# Run tests
composer test

# Run tests with coverage
composer test:coverage

# Run linter
composer lint

# Format code
composer format
```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Quick Guide

[](#quick-guide)

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -am 'Add new feature'`)
4. Push to the branch (`git push origin feature/new-feature`)
5. Create a Pull Request

### Requirements

[](#requirements)

- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT License](LICENSE).

🚀 Roadmap
---------

[](#-roadmap)

- Add settings import/export functionality
- Add settings versioning
- Add real-time settings sync
- Add settings presets
- Add multi-environment support

🙏 Support
---------

[](#-support)

If you find this package helpful, please consider giving it a ⭐️ on GitHub!

### Support the Development

[](#support-the-development)

- [GitHub Sponsors](https://github.com/sponsors/salehye)
- [Buy Me a Coffee](#)
- [PayPal](#)

---

**Built with ❤️ for the Laravel Community**

📞 Contact
---------

[](#-contact)

- **Email**:
- **GitHub**: [@salehye](https://github.com/salehye)
- **Twitter**: [@salehye](#)

🔗 Links
-------

[](#-links)

- [Packagist](https://packagist.org/packages/salehye/settings)
- [GitHub](https://github.com/salehye/settings)
- [Laravel News](https://laravel-news.com/)
- [Laravel Docs](https://laravel.com/docs)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ebed43102dcdc037e65b6e6548f3dcc1aec28e1681913e6415c0f1c4cc0fd34?d=identicon)[salehye](/maintainers/salehye)

---

Top Contributors

[![salehye](https://avatars.githubusercontent.com/u/147006569?v=4)](https://github.com/salehye "salehye (5 commits)")

---

Tags

laravelSettingsconfigmultilingualinertiajs

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/salehye-settings/health.svg)

```
[![Health](https://phpackages.com/badges/salehye-settings/health.svg)](https://phpackages.com/packages/salehye-settings)
```

###  Alternatives

[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

80687.6k](/packages/outhebox-laravel-translations)[asgardcms/platform

The AsgardCms application.

78860.8k](/packages/asgardcms-platform)[velstorelabs/velstore

Velstore - A multi-vendor, multi-lingual Laravel eCommerce boilerplate.

6301.3k](/packages/velstorelabs-velstore)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

3812.2k](/packages/erag-laravel-lang-sync-inertia)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
