【问题标题】:How to change dynamically APP_KEY in config/app.php in laravel如何在 laravel 的 config/app.php 中动态更改 APP_KEY
【发布时间】:2023-01-30 15:59:24
【问题描述】:

基本上我想给不同的不同用户不同的 APP_KEY 所以,当我尝试这样做时,他们会给出致命错误

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    'key' => Auth::User()->APP_KEY

    'cipher' => 'AES-256-CBC',

【问题讨论】:

  • 您可以编辑您的问题并添加异常消息吗?

标签: php laravel laravel-5 eloquent laravel-8


【解决方案1】:

您可以创建一个中间件,并在 handle 方法内部更改配置值...


class SetConfig
{
    /**
     * Handle an incoming request.
     *
     * @param  Request $request
     * @param  Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {


        config()->set("app.key", Auth::User()->APP_KEY);

        return $next($request);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 2015-09-22
    • 2019-08-30
    • 2017-05-13
    相关资源
    最近更新 更多