PHPackages                             samchentw/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. samchentw/settings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

samchentw/settings
==================

4.0.0(4y ago)0207MITPHPPHP ^7.4|^8.0

Since Sep 4Pushed 4y agoCompare

[ Source](https://github.com/samchentw/settings)[ Packagist](https://packagist.org/packages/samchentw/settings)[ RSS](/packages/samchentw-settings/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (25)Used By (0)

Settings
========

[](#settings)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f6aad38d8f381f880b73808a9a8b62a979e2f58fc45c48028a5d2f4e2d5da58c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d6368656e74772f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samchentw/settings)[![tests](https://github.com/samchentw/settings/actions/workflows/tests.yml/badge.svg)](https://github.com/samchentw/settings/actions/workflows/tests.yml)
1.Can store system configuration data
2.Can store other table data, such as: user settings, store settings, etc.

Installation
------------

[](#installation)

`composer require samchentw/settings`

Laravel
-------

[](#laravel)

Publish the config file by running:

```
$ php artisan vendor:publish --provider="Samchentw\Settings\SettingServiceProvider"
```

Create the database table required for this package.

```
$ php artisan migrate
```

If you want to modify the data/settings.json,you can go to 127.0.0.1:8000/samchentw/setting/index
Don't forget to set the setting\_web\_enable in config/setting.php to true. Or use RouterHelper in routes/web.php

```
// routes/web.php

use Samchentw\Settings\Helpers\RouterHelper;

RouterHelper::loadWebRoutes();
```

URL: 127.0.0.1:8000/samchentw/setting/index, like this [![image](https://user-images.githubusercontent.com/89454932/143267343-7feb1974-1983-4a2c-a7cf-3fe91d840f5c.png)](https://user-images.githubusercontent.com/89454932/143267343-7feb1974-1983-4a2c-a7cf-3fe91d840f5c.png)

Settings.json and Model attribute
---------------------------------

[](#settingsjson-and-model-attribute)

```
{
    "display_name": "範例全域參數-數字", //顯示名稱
    "type": "number", // 'string', 'password', 'text', 'number', 'boolean', 'html', 'date', 'date_time','json'
    "sort": 1, //在群組中的排序
    "key": "example.category_limite", //搜尋時需要用到的key值
    "value": 100,   //此kye值的資料
    "provider_key": 0, //如果provider_name為全域變數名稱，值就為0，此欄位可存UserId或其他表Id
    "provider_name": "G"  //全域變數名稱，預設為G，如需更改請到config/setting.php修改
},
{
    "display_name": "測試boolean",
    "type": "boolean",
    "sort": 0,
    "key": "test.boolean",
    "value": true,
    "provider_key": 0,
    "provider_name": "G"
},
{
    "display_name": "測試json",
    "type": "json",
    "sort": 0,
    "key": "test.json",
    "value": [{"value:":"123"},{"value:":"456"},{"value:":"789"}],
    "provider_key": 0,
    "provider_name": "G"
},
{
    "display_name": "測試日期",
    "type": "date",
    "sort": 0,
    "key": "test.date",
    "value": "2021-03-30",
    "provider_key": 0,
    "provider_name": "G"
}
```

Usage
-----

[](#usage)

Simple example

```
    use App\Http\Controllers\Controller;
    use Illuminate\Http\Request;
    use Samchentw\Settings\Contracts\SettingManager;

    class SettingController extends Controller
    {
        private $settingManager;
        public function __construct(SettingManager $SettingManager)
        {
            $this->settingManager = $SettingManager;
        }

        function getSettings(Request $request)
        {
            return $this->settingManager->getByKey('example.title');
        }
    }
```

output:

```
   {
        "display_name": "範例全域參數-標題",
        "type": "string",
        "sort": 1,
        "key": "example.title",
        "value": "後台系統",
        "provider_key": 0,
        "provider_name": "G"
    }
```

If type is boolean

```
    use App\Http\Controllers\Controller;
    use Illuminate\Http\Request;
    use Samchentw\Settings\Contracts\SettingManager;

    class SettingController extends Controller
    {
        private $settingManager;
        public function __construct(SettingManager $SettingManager)
        {
            $this->settingManager = $SettingManager;
        }

        function getSettings(Request $request)
        {
            return $this->settingManager->getByKey('test.boolean');
        }
    }
```

output:

```
   {
        "display_name": "測試boolean",
        "type": "boolean",
        "sort": 0,
        "key": "test.boolean",
        "value": false,
        "provider_key": 0,
        "provider_name": "G"
    }
```

Use provider\_name

```
    $userId= 3 ;
    $this->settingManager->getByKey('example.title','U',$userId);

    $anotherUserId = 4;
    $this->settingManager->setByKey('example.title','使用者自訂標題','U',$anotherUserId);
```

If you must get keys
For example: social.fb social.line social.google

```
    $userId= 3 ;
    $this->settingManager->getByFirstWord('social','U',$userId);

```

Change SettingManager method
----------------------------

[](#change-settingmanager-method)

in the providers/AppServiceProvider

```
    use App\YourNameSpace\MySetting;
    use Samchentw\Settings\Contracts\SettingManager;

    class AppServiceProvider extends ServiceProvider
    {

        public function boot()
        {
            app()->singleton(
                SettingManager::class,
                MySetting::class
            );

```

MySetting.php

```
    use Samchentw\Settings\Contracts\SettingManager;
    use Samchentw\Settings\Models\Setting;

    class MySetting implements SettingManager
    {

        public function getByKey(string $key, $provider_name = '', $provider_key = null)
        {
            //your code....
        }

    //your code....
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 88.2% 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

Every ~7 days

Recently: every ~24 days

Total

24

Last Release

1539d ago

Major Versions

1.0.2 → 2.0.02021-09-08

2.8.0 → 3.0.02021-11-24

3.5.0 → 4.0.02022-03-01

PHP version history (2 changes)1.0.1PHP ^7.3|^8.0

4.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89454932?v=4)[samchentw](/maintainers/samchentw)[@samchentw](https://github.com/samchentw)

---

Top Contributors

[![samchentw](https://avatars.githubusercontent.com/u/89454932?v=4)](https://github.com/samchentw "samchentw (45 commits)")[![samchenwater](https://avatars.githubusercontent.com/u/43718347?v=4)](https://github.com/samchenwater "samchenwater (6 commits)")

---

Tags

dependency-injectionlaravelmodel

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[mrmarchone/laravel-auto-crud

Laravel Auto CRUD helps you streamline development and save time.

28711.8k2](/packages/mrmarchone-laravel-auto-crud)

PHPackages © 2026

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