Seeding settings

On a fresh DB after a migrate:fresh --seed calling TwillAppSettings::get gives me a Illuminate\Support\ItemNotFoundException error. I was hoping to seed them via a migration or seeder or set default values but can't see anything obvious to do so in the docs.
10 Replies
RacoonMittens
RacoonMittensOP7mo ago
For context the specific settings field I'm getting that gives me that error is a browser multi-select Hi @ifox just tagging since I haven't had a response. Maybe I should have put this in #❓questions like last time I have gotten around this with a wrapper class but feels hacky to need to do this:
<?php

namespace App\Facades;

use A17\Twill\Facades\TwillAppSettings as FacadesTwillAppSettings;

class TwillAppSettings extends FacadesTwillAppSettings
{
public static function get($identifier, $default = null)
{
try {
return parent::get($identifier);
} catch (\Exception $e) {
return $default;
}
}
}
<?php

namespace App\Facades;

use A17\Twill\Facades\TwillAppSettings as FacadesTwillAppSettings;

class TwillAppSettings extends FacadesTwillAppSettings
{
public static function get($identifier, $default = null)
{
try {
return parent::get($identifier);
} catch (\Exception $e) {
return $default;
}
}
}
ifox
ifox7mo ago
Hi @RacoonMittens you're right, there should be a seeder for settings. If you go to the CMS settings, they are seeded, but not before that. I also think we should implement get like you did. We'll revisit this.
RacoonMittens
RacoonMittensOP7mo ago
Is there a simple way to use that seeder? I looked around but didn't find anything that stood out For now my wrapper is working like a charm so I'm happy either way
ifox
ifox7mo ago
GitHub
twill/src/Services/Settings/SettingsGroup.php at f365a13e4929ba90bb...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
ifox
ifox7mo ago
GitHub
twill/src/Http/Controllers/Admin/AppSettingsController.php at f365a...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
RacoonMittens
RacoonMittensOP7mo ago
Ah thats really helpful. So in that case, I can just put this block in my AppServiceProvider boot function to make sure they exist before I try to use them anywhere
foreach (TwillAppSettings::getAllGroups() as $group) {
$group->boot();
}
foreach (TwillAppSettings::getAllGroups() as $group) {
$group->boot();
}
thanks for the help oh actually that boot block doesn't work 🤔 Think I'll just stick with my custom facade wrapper for now
ifox
ifox7mo ago
I think we're talking about 2 different issues. Your settings are already booted, but retrieving a browser field is failing if it's empty? Even if you save the settings form with an empty browser?
RacoonMittens
RacoonMittensOP7mo ago
If I save the form with an empty browser it works fine, but up until that point I get errors from retrieving that setting
ifox
ifox7mo ago
ok yeah, makes sense
RacoonMittens
RacoonMittensOP7mo ago
My issue is that I am trying to check this setting in a generic page middleware that populates some nav elements so I can't get to the settings page (without commenting out a block of code in the middleware) to even save the blank version
Want results from more Discord servers?
Add your server