Global helpers
admin()
Returns the logged administrator ornull.
autoAjax()
Returns a JSON response builder for messages, errors and store data.Frontend editor
uploadable(), linkable() and encryptText(): available with the crudadmin/website package (composer require crudadmin/website).Other helpers
_(), localeUrl(), switchLocale(), localizedRoutes()) are described in Localization.
Text obfuscation
encryptText($text) obfuscates e-mails or phone numbers as base64 for frontend decoding. It is not encryption and should not be used to protect secrets. Decoding on the website is described in Obfuscated e-mails.
Admin facade
Request type
Admin::isAdmin() is true for URLs starting with /admin. Admin::isFrontend() is true for other HTTP requests, never in console.
Models
Request cache
A cache living for one request, shared by the whole administration.Log
Admin::isEnabledLocalization(), Admin::isEnabledAdminLocalization(), Admin::isHistoryEnabled() and Admin::isRolesEnabled(), see Configuration.
Admin events
Migration events
fire_after_migration runs after the table was migrated, fire_after_all after all tables. The _noScheme suffix runs the callback without the schema builder. Callbacks run once. For hooks inside the model see migration hooks.
Generator events
admin:model fires admin.command.model.create.stub_path, stub, namespaces, parameters, fields and options. admin:module fires admin.command.module.create.stub_path, stub and options. Arguments are passed by reference.
Extending from packages
Registering models
Package service provider
A package has one service provider extendingAdmin\Providers\AdminPackageServiceProvider. It declares what the package brings, the base provider registers it and keeps it working with php artisan optimize: config files are merged only when the config is not cached, route files are loaded only when the routes are not cached.
src/Providers/AppServiceProvider.php
models():
configure() and models() run once for the whole process under Laravel Octane (or once in config:cache), they read the config only, never the request, the session or the database. Settings set in boot() on a facade of a service bound per request are lost from the first Octane request on, keep them in static properties or in the config.
Keep register() and boot() for other work (publishes, views, macros) and call parent::register() / parent::boot() first. Do not add separate config, route or event providers, and do not extend Laravel’s RouteServiceProvider or EventServiceProvider: with the application skeleton of Laravel 11 they load all routes of the application again and add the email verification listener once more.
The config of $adminConfig looks like this, the groups of a package are [Class::class, 'method'] callables resolved late for translations:
src/Config/admin.php
php artisan optimize: no closures in config files, env() only in config files, config()->set() only in configure(), routes only with controller actions and unique names prefixed by the package.