Comments (6)
For anyone else coming here looking for the answer - you need to this:
Add this to each file using Settings:
use Backpack\Settings\app\Models\Setting;
Then use this:
Setting::get('my-setting-name');
instead of
config('settings.my-setting-name');
and it'll work everywhere.
Personally I've just copied this bit from the Service Provider and put it into my own AppServiceProvider:
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->loadSettings();
}
/**
* The default Backpack Settings module does not work on the Command Line
* because it fails if you don't have a database. Since we do have a
* database it's safe for us to use it. This code is copied from the
* Backpack\Settings\SettingsServiceProvider::boot() method with the
* runningInConsole() conditional removed.
*
* @return void
*/
public function loadSettings()
{
if (count(Schema::getColumnListing('settings'))) {
// get all settings from the database
$settings = Setting::all();
// bind all settings to the Laravel config, so you can call them like
// Config::get('settings.contact_email')
foreach ($settings as $key => $setting) {
Config::set('settings.'.$setting->key, $setting->value);
}
}
}
from settings.
Hello there! Thanks for opening your first issue on this repo!
Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.
Backpack communication mediums:
- Bug Reports, Feature Requests - Github Issues (here);
- Quick help (How do I do X) - Gitter Chatroom;
- Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the
backpack-for-laravel
tag;
Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.
Thank you!
--
Justin Case
The Backpack Robot
from settings.
I've just seen this has already been discussed, and potentially fixed (though I'm not getting it yet).
https://github.com/Laravel-Backpack/Settings/issues?utf8=%E2%9C%93&q=is%3Aissue+console
#70
#19
So closing this, as a dupe.
from settings.
@Patabugen thanks for sharing your solution with everyone! I bet someone will be very grateful to find your post.
Actually, you don't really need the use statement. This package's service provider already adds the Setting
alias to Laravel's default configuration. So you should be able to use Setting::get()
reliably inside you app anywhere, without having to explicitly use the class. This is way better than using Config::get('setting.your_key')
so I'll update the docs right now to put this method as the default one.
Thanks again, cheers!
from settings.
@tabacitu i found out today while accessing settings values in a homemade artsan command, that i had to explicitly "use Backpack\Settings\app\Models\Setting". Seems Laravel 8 does not do auto-namespaces any more.
from settings.
Hello there @caveman99
It's totally expected outcome. config()
is part of app instance itself and is not available on console commands, for that you'd need to use Config::get('your_key')
Best,
Pedro
from settings.
Related Issues (20)
- Home example should have translatable form HOT 3
- Using table field cause ViewException in latest version (Probably have something to do with Backpack 4.1) HOT 5
- Uploading file to settings? HOT 1
- How to setup repeatable field HOT 2
- MongoDB compatibility HOT 3
- Replace screenshot with one from Backpack 4.1
- type checkbox is not working shows wyswyg HOT 4
- Licence HOT 3
- Multi language support for field edit. HOT 3
- The package publishes in the resources dir, but Laravel 9 defaults to lang HOT 1
- Is there a reason you don't allow this to run in CLI mode? HOT 2
- change config HOT 2
- How is supposed to work with a select field? HOT 4
- The length of the line for the setting name HOT 3
- Having issue with images HOT 2
- Suggestion/question about addon HOT 2
- Maximum field length for a setting value HOT 6
- Add Setting button is missing HOT 4
- [Feature Req] Cache settings HOT 6
- PHP 7.4 compatibility HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from settings.