dqsxsmi3704 2016-12-25 08:01
浏览 127
已采纳

如何在laravel中添加和更新配置变量

I have a config variable file which I'm using it in my controllers instead of mysql for faster performance.

But my problem is that I can only read from this config file and I can not add or update any value from it.

any suggestion how to update or add new values to this variable file :

my variable file which is stored in /config/Banners_size.php:

return [
    "normal_x970h90" => [
        'status' => 'enable',
        'value' => '500'
    ],

    "normal_x234h60" => [
        'status' => 'enable',
        'value' => '500'
    ],
]

my php code to add new array to it which is not working :

    $banners = Config('Banners_size');
    $banner = array(
        $request->input('size') => [
            'status' => $request->input('status'),
             'value' => $request->input('cost')
        ]
    );

   $bannerinfo = array_merge($banners, $banner);

   Config('Banners_size' , $bannerinfo);
  • 写回答

2条回答 默认 最新

  • duanlu0559 2016-12-25 08:43
    关注

    The configuration files are read only files, you cannot add parameters to it programmatically.

    $banners = config('Banners_size');
    
    config('Banners_size' , $bannerinfo);
    

    The above two lines, will act the same, and will both return the value of Banner_size.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看