Settings
This lets you create a settings page in the admin area and also provides a facade for accessing those settings.
Installation
Add the ServiceProvider to config/app.php.
Yadda\Enso\EnsoSettingsServiceProvider::class,
Add an alias to the Settings Facade.
'EnsoSettings' => Yadda\Enso\Settings\Facades\EnsoSettings::class,
Publish the CRUD.
php artisan vendor:publish
Run the migration to create the enso_settings table.
php artisan migrate
Adding Settings
Settings are managed as any other crud. For example:
class Setting extends BaseCrud
{
public function create(Form $form) {
$form = parent::create($form);
$form
->getSectionByName('main')
->setLabel('Global')
->addField([
(new TextField('some_setting'))
]);
$form->addSections([
(new CollectionSection('social'))
->addFields([
(new TextField('twitter_url')),
(new TextField('instagram_url')),
(new TextField('phone')),
(new TextField('email')),
]);
]);
return $form;
}
}
Accessing Settings
EnsoSettings::get('some_setting', 'Fallback for if some_setting does not exist.');
Creating/Updating Settings
This needs some work. You need to do something like this:
EnsoSettings::set('some_setting', 'Here is a setting', [
'type' => 'scalar',
'content' => [
'id' => 'some_setting',
],
]);
Except that that doesn't set the ID correctly. So you'll need to do something like this:
/**
* Temporary feature to set settings as the Current implementation
* doesn't key new items properly.
*
* @param string $name
* @param mixed $value
* @param array $data_type - Get from instance of Field
*
* @return void
*/
protected function setSetting($name, $value, $data_type)
{
$this->app->make('ensosettings')->set($name, $value, $data_type);
$this->app->make('ensosettings')->all()->put($name, $this->app->make('ensosettings')->getSetting(0));
$this->app->make('ensosettings')->all()->forget(0);
}