By default your setting group is editable through the admin by a generated edit page. You cannot remove this generated edit page but you can stop users from being able to edit the settings using it. It’s important to note that if you disable editing through this edit page that users can still edit the settings manually through the storage json file.
To make your setting group not editable you should call the notEditable method when defining your group.
<?php
namespace Acme\MyModule;
use Aero\Common\Facades\Settings;
use Aero\Common\Providers\ModuleServiceProvider;
use Aero\Common\Settings\SettingGroup;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
Settings::group('acme-my-module', function (SettingGroup $group) {
$group->string('denied_message');
$group->array('allow_list');
$group->boolean('allow_list_enabled');
$group->notEditable();
});
}
}
Validation Rules
These are helper methods that map to their equivalent Laravel Validation Rules. It’s important to note that these validation rules apply when saving through the generated admin edit page. These rules do not stop people from manually editing the settings storage json file to have invalid values.
Rule | Works For |
---|---|
$group->string('key')->required(); | All |
$group->string('key')->between($min, $max); | String, Integer, Float, Array, Encrypted |
$group->string('key')->min($min); | String, Integer, Float, Array, Encrypted |
$group->string('key')->max($max); | String, Integer, Float, Array, Encrypted |
$group->string('key')->size($size); | String, Integer, Float, Array, Encrypted |
$group->string('key')->greaterThan($size); | String, Integer, Float, Array, Encrypted |
$group->string('key')->lessThan($size); | String, Integer, Float, Array, Encrypted |
$group->string('key')->in($needles); | String, Integer, Float |
$group->string('key')->email(); | String, Encrypted |
$group->string('key')->uuid(); | String, Encrypted |
$group->string('key')->url(); | String, Encrypted |
$group->string('key')->ip(); | String, Encrypted |
$group->string('key')->startsWith($needle); | String, Encrypted |
$group->string('key')->startsWithOneOf($needles); | String, Encrypted |
$group->float('key')->step($step); | Float |
$group->date('key')->beforeToday(); | Date |
$group->date('key')->before($date); | Date |
$group->date('key')->afterToday(); | Date |
$group->date('key')->after($date); | Date |
Methods
Method | For | Description |
---|---|---|
$group->title($title); | - | Set the title shown in the list of settings (by default this is generated from the group name). |
$group->summary($summary); | - | Set the summary shown in the list of settings. |
$group->notEditable(); | - | Disable editing through the generated admin page. |
$group->string('key')->label($label); | All | Set the label for the edit field (by default this is generated from the settings key). |
$group->string('key')->hint($hint); | All | Add a helpful hint to the edit field. |
$group->string('key')->textarea(); | String | Make the string field appear as a textarea. |
$group->string('key')->wysiwyg(); | String | Make the string field appear as a wysiwyg. |
$group->eloquent('order_status', OrderStatus::class)->searchField($field); | Eloquent | Define the field used for searching in the searchable select. |
$group->eloquent('order_status', OrderStatus::class)->searchFields($field); | Eloquent | Define multiple fields used for searching in the searchable select (first field is the value). |
$group->array('key')->associative(); | Array | Define the array as an associative array - an array that has a key and value. |
$group->array('key')->definition($definition); | Array | Set a custom definition for your array (link:section below this). |
Complex Array Definitions
If you have a complex array (an array of arrays that have multiple keys), you need to define the contents of the array and any validation for each key.
Here is a code example that defines an additional_checkboxes array that is an array of arrays. The child arrays have a text key (that has validation ensuring it is a string and required) and a required key (that has validation ensuring it is a boolean).
Although this example uses the string, required, and boolean rules you can use any Laravel Validation rule.
<?php
namespace Acme\MyModule;
use Aero\Common\Facades\Settings;
use Aero\Common\Providers\ModuleServiceProvider;
use Aero\Common\Settings\SettingGroup;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
Settings::group('acme-my-module', function (SettingGroup $group) {
$group->array('additional_checkboxes')->definition([
'text' => ['string', 'required'],
'required' => ['boolean']
]);
});
}
}