The best approach would be to add an extension so that your changes persist across upgrades. Here is the scaffolding for an extension which will let you add fields to an admin model, form and list.
<?php
namespace YourNamespace\YourExtension;
use Event;
use Admin\Models\Menus_model;
use Admin\Widgets\Form;
use System\Classes\BaseExtension;
class Extension extends BaseExtension
{
public $myField = 'my-field-name';
public function boot()
{
// extend fillable
Menus_model::extend(function ($model) {
$model->fillable(array_merge($model->getFillable(), [$this->myField]));
});
// extend validation in odels
Event::listen('system.formRequest.extendValidator', function ($formRequest, $dataHolder) {
if ($formRequest instanceof \Admin\Requests\Menu) {
$dataHolder->rules[] = [$this->myField, 'Field label', 'required']; // see laravel rules: https://laravel.com/docs/8.x/validation#available-validation-rules
}
});
// this is fired before the form is output, allowing you to extend the default config
Event::listen('admin.form.extendFieldsBefore', function (Form $form)
{
// if its a main menu form (ie not a modal)
if ($form->model instanceof Menus_model && isset($form->tabs['fields']) && array_key_exists('menu_name', $form->tabs['fields'])) {
$form->tabs['fields'][$this->myField] = [
'label' => 'Field label',
'type' => 'text',
'tab' => 'Tab label',
]; // checkout out app/admin/models/config/* for more examples of field types
}
});
// if you want to add columns to a list in the admin panel
Event::listen('admin.list.extendColumns', function (&$widget)
{
if ($widget->getController() instanceof \Admin\Controllers\Menus){
$widget->addColumns(['field_name' => [
'invisible' => false,
'label' => 'Your label',
'type' => 'text',
]]); // checkout out app/admin/models/config/* for more examples of list column types
}
});
}
}