Admin rules
Rules are reusable classes with hooks running before and after records are created, updated, deleted or published.app/Admin/Rules and registered on the model:
app/Models/Invoice.php
app/Admin/Rules/SetInvoiceNumber.php
rules($row) method, or extended with setRulesProperty($rules).
Rule hooks
Every method receives the record. Saving the record inside a rule does not run the rules again.
Stop the action with an error:
Where rules run
$frontend = true also run in console (commands, queues, scheduler).
Disable rules for one record, or silence some of them:
Changing the admin form
$this->isFieldDirty('price') returns true when the field was changed in the admin form.
Admin hooks
Methods called only by actions in the administration, not byModel::create(), update() or delete() in your code.
app/Models/Partner.php
Eloquent events
Standard Eloquent events fire for admin actions too, before the admin hooks:saving, creating, created, saved, then onCreate, and deleting, deleted, then onDelete. Use them for logic which has to run everywhere.
Modules
Modules are reusable classes extending admin models with fields, parameters, scopes and responses.app/Admin/Modules. Modules in the module directories are loaded for all admin models, isActive() decides for which of them the module runs.
app/Admin/Modules/BannerModule.php
app/Models/Page.php
$this->getModel() returns the model, or the listed row, the module currently runs for.
Registering a module on one model
app/Models/Product.php
AdminModel::addGlobalModule(PriceModule::class) in a service provider adds a module to all models.