PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] How to add and update config varaibles in laravel

 February 08, 2022     arrays, config, laravel-5.3, php, variables     No comments   

Issue

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);

Solution

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.



Answered By - Mina Abadir
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing