Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

Config::set() still available in Laravel 5.3?

I've seen some examples on the net where they use Config::set() like here https://laracasts.com/discuss/channels/laravel/config-set-not-working

I tried it and I didn't get any errors, however my settings name is still empty, is this working in Laravel 5.3?

\Config::set('settings.name', 'Test');

inside config/settings.php

return [
    'name' => ''
];
0 likes
9 replies
nikocraft's avatar

I've tried this also config(['settings.name' => 'test']); does nothing to the config/settings.php name field, it still empty. Any other ideas? Or maybe I have missunderstood config(['settings.name' => 'test']); it doesn't save to the config file? That is what I want to do

shez1983's avatar
 \Config::get('services.mailgun');
=> [
     "domain" => null,
     "secret" => null,
   ]
>>> 

seems to be working for me in 5.3 (not sure about setting it first programatically & then getting it)

SaeedPrez's avatar

@maxnb it doesn't change the config file. Why would you want to do that anyways?

nikocraft's avatar

I am adding possibility for user to set some settings for the application from the backend. I dont won't to save this setting in the database since it would then be called on every pageload, if I store it in config file it easy to get it just like config('settings.somesetting'). I found a package that does this but I got confused by people talking about \Config::set('settings.name', 'Test'); I thougth that would actually write to file and belived that Laravel had this functionallity without an extra package.

SaeedPrez's avatar

Changing the config file will affect the whole application which could potentially cause unwanted behavior or scaling problems . If your users are logged in, then Laravel will query the database on every request anyways so adding a column to the user table where you store some config value for that specific user won't affect your application.

Also keep in mind that this isn't 1995 where CPU was a limited resource. Today you can get a VPS for like $5/mo and unless you're expecting your application to handle thousands of requests in a short amount of time or if you're querying huge database tables with millions of rows of data you won't notice any slow downs because of an additional database query.

Edit: If you however really need to set some permanent config values for your application, you would probably be better of changing the .env file.

nikocraft's avatar

Actually this will just be something admin user does. I am building an image sharing application, check it out here

imageshare.code4fun.io
email: [email protected]
pass: 'password'

When logged in click on the admin username on the top right corner and click on Admin.

I am selling this application and customers have requested that I add socialsharing buttons, I looked around and found some packages which did this but then I found something better https://www.addthis.com/get/share it allows me to create socialsharing buttons and add as many or as few social networks I want. Only problem with it is that it generates a js file that I need to add to my application before end of body tag. However if I do this and leave it at this my customers will actually just be tied to my addthis.com account since the code generated and the look and placement of items is specific to me. If some user wanted to add for example digg.com as an option to share they would be out of luck since I hardcoded my own addthis.com account in the application. I want them to be insert their own addthis link and I provide that in the settings area of the dashboard, and save that to config file settings.php instead to database since I don't want to be calling database each time I need to get this link and that will happen frequently when normal users browse the site and enter a link like http://imageshare.code4fun.io/album/1ODQY08

SaeedPrez's avatar

I've said what I have to say and at the end of the day, it's your application.

Good luck.

shez1983's avatar

i agree... database is the way to go.. wont repeat what @SaeedPrez said already.

The other hacky way would be to create a folder in app/storage and then create one file per user.. and read/write from there..

Please or to participate in this conversation.