定制 hepplerdotnet/laravel-config-override 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hepplerdotnet/laravel-config-override

Composer 安装命令:

composer require hepplerdotnet/laravel-config-override

包简介

Package to store Laravel Configuration in Database

README 文档

README

Store Laravel Configuration in Database and use it thru config() helper

Important

This Package uses Illuminate\Vendor\HepplerDotNet\Providers\ConfigurationProvider

Before you start yelling "Using Illuminate namespace is bad practice!".

You're right, but let's take a look at Illuminate\Foundation\Application::registerConfiguredProviders

/**
     * Register all of the configured providers.
     *
     * @return void
     */
    public function registerConfiguredProviders()
    {
        $providers = Collection::make($this->make('config')->get('app.providers'))
                        ->partition(function ($provider) {
                            return strpos($provider, 'Illuminate\\') === 0;
                        });

        $providers->splice(1, 0, [$this->make(PackageManifest::class)->providers()]);

        (new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))
                    ->load($providers->collapse()->toArray());
    }
  1. It creates a collection from your App config providers array
  2. Splits this array in 2 chunks [Everything that starts with Illuminate, rest of it]
  3. Adds all the composer packages service providers in between

This package derived from one of my projects which had some requirements:

  1. Login against Active Directory (solved easily with https://ldaprecord.com/docs/laravel/v2/)
  2. Make the whole App configuration maintainable thru Webgui, including ldap configuration

All "regular" options to register a Service Provider failed at some point, either Auth facade failed or LDAP failed because config() had no access to the configuration from database at this point.

So using Illuminate namespace was the only working solution. Period.

Installation

Requires at least laravel/framework 8.37 because of anonymous migrations

Run composer require hepplerdotnet/laravel-config-override

Note

key => values from database will have precedence over config or .env file!

Groups will be merged with existing configuration

Usage

Let's say you would change the app locale

use HepplerDotNet\LaravelConfigOverride\Models\Group;
Group::create(["name" => "app", "root" => true, "active" => true])
  ->entries()
  ->create(["key" => "locale", "value" => "de", "type" => "String"]);

Now you can access it with config("app.locale")

Or a more complex example with nested groups

Group::create(["name" => "mail", "root" => true, "active" => true])
    ->groups()->create(["name" => "mailers", "root" => false, "active" => true])
    ->groups()->create(["name" => "smtp", "root" => false, "active" => true])
    ->entries()->create(["key" => "host","value" => "localhost", "type" => "String"]);

Now you can access it with config("mail.mailers.smtp.host")

The Models

Group

Property Description Values
name Name analog to config file e.g. app or mail String
root Group is root element true or false
active Configuration is active and should be loaded true or false

Entry

Property Description Values
key Configuration Key String
value Configuration Value String, Password, Integer, Boolean, Array
type Value type String, Password, Integer, Boolean, Array

Type Password will be stored encrypted in database!

Config

Config is not a real Eloquent Model, it's just a Class which builds the config from database

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固