Support the ongoing development of Laravel.io →
Input Database
Last updated 2 years ago.
0

I wouldn't try combing the default Config class with a user-facing config file. Sounds like a really bad idea unless you have a good reason for it. Just my 2 cents though.

Last updated 2 years ago.
0

mrberggg said:

I wouldn't try combing the default Config class with a user-facing config file. Sounds like a really bad idea unless you have a good reason for it. Just my 2 cents though.

I don't require the class to be called Config, I mean. MyConfig would be just fine, I just need it to be stored on database instead of php files.

Last updated 2 years ago.
0
Solution

This setup stores the database result in the cache for fast access. Just remember to forget the cache when changing the data. (store/update)

http://laravel.io/bin/WjY

With the above setup you can use the Config class

echo Config::get('settings.key'); // value

small correction, the file needs to be placed in app/config/settings.php, this is wrong in the link

Last updated 2 years ago.
0

Why not just call it "Settings" or "AppSettings" or something similar?

Last updated 2 years ago.
0

zenry said:

This setup stores the database result in the cache for fast access. Just remember to forget the cache when changing the data. (store/update)

http://laravel.io/bin/WjY

With the above setup you can use the Config class

echo Config::get('settings.key'); // value

small correction, the file needs to be placed in app/config/settings.php, this is wrong in the link

This seems to help a lot, but it is confusing, Setting is an Eloquent model?

Last updated 2 years ago.
0

This seems to help a lot, but it is confusing, Setting is an Eloquent model?

yes Setting is a Eloquent Model, I used Setting::all() but you can add an user_id and do something like Setting::where('user_id', 1)->get()

the table looks like

  • id
  • name
  • value
  • created_at
  • updated_at
Last updated 2 years ago.
0

fyi you can store an array in value, just create a Mutator (http://laravel.com/docs/eloquent#accessors-and-mutators) that serializes the array before inserting (setValueAtrribute) and unseriailizes the array when using (getValueAttribute)

Last updated 2 years ago.
0

Just throwing this package out there, might save you some headache.

https://bitbucket.org/hailwoodnz/database-config-loader

Last updated 2 years ago.
0

Thanks zenry, after some coding I figured it out :D

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ranisalt ranisalt Joined 10 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.