Laravel Config::set Persist Through Requests?

前端 未结 2 1797
名媛妹妹
名媛妹妹 2021-01-23 00:03

I have been building a web application that tracks statistics. These statistics can range between different companies.
I decided to use a main database to house all of the l

2条回答
  •  佛祖请我去吃肉
    2021-01-23 00:20

    Well, you can't actually use config for this.

    Configuration values that are set at run-time are only set for the current request, and will not be carried over to subsequent requests.

    Laravel documentation reference.

    Workaround

    As a hacky workaround, and if you are not willing to use your main database to store the company database connection data, you could use a custom configuration file that you could update on run-time.

    This is very similar to how the original config file works and it should keep the data persistently. However you have to build a control mechanism around it to keep the entries unique and consistent:

    Update Config on Runtime Persistently

    You could also look for a package for this so you dont have to re-invent the wheel. Check laravel-config-writer (disclaimer: never personally used it).

提交回复
热议问题