Extension Development
An extension is a Composer package with a service provider, an Extension class and, usually, its own routes and views. This page shows how to build one that installs cleanly, works on every supported Laravel version and fits every template.
Generate a skeleton
php artisan admin:extend my-vendor/my-extension
This creates, under admin.extension_dir (default app/Admin/Extensions):
my-vendor/my-extension/
├── composer.json
├── README.md
├── LICENSE
├── database/migrations/
├── database/seeds/
├── resources/assets/
├── resources/views/index.blade.php
├── routes/web.php
└── src/
├── MyExtension.php
├── MyExtensionServiceProvider.php
└── Http/Controllers/MyExtensionController.php
--namespace= sets the PHP namespace. Add the folder to your app's composer.json as a path repository to install it while you develop.
The Extension class
namespace MyVendor\MyExtension;
use SuperAdmin\Admin\Extension;
class MyExtension extends Extension
{
public $name = 'my-extension';
public $views = __DIR__.'/../resources/views';
public $assets = __DIR__.'/../resources/assets';
public $menu = [
'title' => 'My Extension',
'path' => 'my-extension',
'icon' => 'icon-puzzle-piece',
];
public $permission = [
'name' => 'My Extension',
'slug' => 'ext.my-extension',
'path' => ['/my-extension*'],
];
}
MyExtension::boot()registers the extension under$name, returnsfalsewhen it is disabled (admin.extensions.my-extension.enable = false), registers$viewsfor the active template and adds$css/$js.MyExtension::config('key', $default)readsadmin.extensions.my-extension.key.php artisan admin:import my-extensioncreates$menu(with optionalchildren) and$permission. Importing twice does not create duplicates.MyExtension::routes(__DIR__.'/../routes/web.php')loads routes inside the admin prefix and middleware;admin.extensions.my-extension.routecan override them.
The service provider
use Illuminate\Support\ServiceProvider;
use SuperAdmin\Admin\Facades\Admin;
class MyExtensionServiceProvider extends ServiceProvider
{
public function boot(MyExtension $extension): void
{
if (! MyExtension::boot()) {
return;
}
// Views follow the active template; see "Templates" below.
Admin::template()->extensionViews('my-extension', $extension->views());
if ($this->app->runningInConsole() && $assets = $extension->assets()) {
$this->publishes([$assets => public_path('vendor/my-extension')], 'my-extension');
}
$this->app->booted(function () {
MyExtension::routes(__DIR__.'/../routes/web.php');
});
}
}
Register it for package discovery in composer.json:
"extra": {
"laravel": {
"providers": ["MyVendor\\MyExtension\\MyExtensionServiceProvider"]
}
}
Templates
Write views with the shared class vocabulary (Bootstrap 5 class names such as card, card-header, table table-hover, badge bg-success, nav nav-pills, d-flex), colours from the --sa-* CSS variables, and data-bs-toggle for collapse, tabs, modals and dropdowns. No jQuery. Then the extension looks right in every template. Check your views with:
php artisan admin:lint-views path/to/my-extension/resources --ignore=my-ext-
A template can restyle one of your views without touching the extension, by adding resources/views/<template>/extensions/my-extension/<view>.blade.php. You can also ship a template-specific variant yourself in resources/views/<template>/. See Templates for the lookup order.
Supporting Laravel 8 to 13
Super Admin supports PHP 8.0+ and Laravel 8 to 13; an official extension should too.
composer.json:
"require": {
"php": "^8.0",
"super-admin-org/super-admin": "^1.3",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0|^13.0"
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"pestphp/pest": "^1.0|^2.0|^3.0|^4.0"
}
Things that differ across those versions:
| Area | Watch out for |
|---|---|
| Helpers | array_get(), str_slug() and friends were removed in Laravel 6; use Arr:: and Str::. |
| Requests | Use $request->input(); Symfony 7.4 deprecates Request::get(). |
| Files | Laravel 8 uses Flysystem 1, Laravel 9+ Flysystem 3. Go through Storage methods, never through adapters. |
| Redis | Laravel's default client is phpredis; support both it and predis, or say which one you need. |
| App structure | Laravel 11+ has no app/Console/Kernel.php or app/Exceptions/Handler.php; schedules live in routes/console.php, exception hooks in bootstrap/app.php, API routes only after php artisan install:api. |
| PHP 8.x | No final private methods, no dynamic properties (8.2), explicit ?Type for nullable parameters (8.4), return types on Iterator/ArrayAccess methods (8.1). |
| Migrations | Use anonymous migration classes, or unique class names. |
Test with a matrix of Laravel versions using Orchestra Testbench:
| Laravel | Testbench | PHP |
|---|---|---|
| 8 | 6.x | 8.0 |
| 9 | 7.x | 8.1 |
| 10 | 8.x | 8.2 |
| 11 | 9.x | 8.3 |
| 12 | 10.x | 8.4 |
| 13 | 11.x | 8.4 |
Security checklist
Extensions run with an administrator's privileges, so:
- Validate every request value that names a file, class, view, method or command against an allow-list.
- Escape output:
{{ }}in Blade,textContent(notinnerHTML) in JavaScript,e()when building HTML in PHP. - Keep file operations inside the configured disk; never pass a request path to
File::/response()->download()directly. - Give each tool its own permission, and make developer tools (terminals, code generators, raw consoles) off by default in production.
- Never store passwords, tokens or session cookies.
Publish
Tag releases (v1.2.0) so composer require works with stable minimum stability, keep a CHANGELOG.md, and add the extension to the Extensions list.