Building a Perfex CRM Next Module: Laravel, Livewire and the Module Definition
A Next module is a Laravel package with a module.json and one definition class. Scaffolding, the builder API, and why the requires field should stay empty.
php artisan module:make MyFeature Item --type=resource
php artisan module:migrate MyFeature
That is a working module with a model, migration, policy, resource, list and record pages, create and edit forms, routes, menu entries and permissions. Everything after this is detail - but the detail is where the difference between a Classic module and a Next module lives.
We build and sell Perfex modules and are rewriting our catalogue for Next, so this is our own working notes rather than a neutral survey.
The part that surprises Classic developers
A Classic module is a folder with a header comment, controllers, views, and a hooks file that attaches to the application with hooks::add_action. It sits beside the CRM. Its pages are its own, its tables are its own, and integration means posting links into menus.
A Next module is a Laravel package that extends the CRM itself. The difference shows up immediately in the one file that matters:
namespace Modules\MyFeature;
use Modules\Core\Module\ModuleBuilder;
use Modules\Core\Module\ModuleDefinition;
final class MyFeatureModule extends ModuleDefinition
{
public function define(ModuleBuilder $module): void
{
$module
->permissions(...)
->menu(...)
->settingsSection('work', ...)
->widgets(SyncStatusWidget::class)
->listen(RecordCreated::class, SyncNewContact::class)
->extendResource(InvoiceResource::class, ...)
->extendModel(Contact::class, ...);
}
}
One class declares everything the module adds, and it runs only while the module is enabled. Disable the module and its menus, permissions, settings and extensions vanish with no cleanup code. That single property removes an entire category of Classic bugs, where a disabled module left half its menu entries behind.
Code that must run while the module is disabled goes in bootstrap/module.php instead, which is also where the enable, disable and delete callbacks live.
Scaffolding profiles
--type= picks how much you start with.
| Profile | Generates | Use for |
|---|---|---|
minimal (default) | Definition, provider, module.json, composer.json, routes, config, translations | Shared infrastructure, extensions of other modules |
resource | Plus model, migration, factory, policy, Resource, list and record pages, forms, routes, menu entries, permissions | A real object: tickets, assets, work orders |
settings | Plus a settings dialog and its entry on the Settings page, gated by {module}.manage | Configuration-only modules |
payment-gateway | Plus a gateway driver registered with Billing | Stripe, PayPal drivers |
integration | Plus an OAuth 2 integration with its app dialog in Settings | Slack, HubSpot, QuickBooks |
integration-api-key | Same, but connected with an API key | Mailchimp, SendGrid |
Add --with-vite when you need your own JS or CSS. Generators fill in the rest later: module:make-model, module:make-migration, module:make-policy, module:make-core-resource, and make:livewire myfeature::my-settings --class.
Layout and naming
| Convention | Example |
|---|---|
| Folder | PascalCase - Tickets, Billing |
module.json alias | lowercase - tickets, billing |
| Namespace | Modules\Tickets\... |
| View and lang prefix | tickets::app.title |
modules/MyFeature/
├── app/
│ ├── MyFeatureModule.php # the definition
│ ├── Providers/
│ └── Livewire/, Models/, Policies/, Resources/, ...
├── bootstrap/module.php # enable/disable/delete callbacks
├── config/config.php
├── database/migrations/
├── lang/en/app.php
├── public/
├── resources/views/
├── routes/ # admin.php, frontend.php, api.php, webhooks.php
├── composer.json
└── module.json
Perfex reads each module’s own composer.json autoload section, so you never touch the root one. Third-party packages go in the module’s own vendor/. After changing autoload, run php artisan core:flush-module-autoload --rebuild.
Find your own files with module_path('MyFeature', 'resources/data.json'), never a hard-coded modules/MyFeature - hosted installs can keep uploaded modules elsewhere.
Routes, and the four files
Perfex applies the prefix and middleware; you do not.
| File | Prefix | Middleware | Route names |
|---|---|---|---|
routes/admin.php | /admin | web, auth | admin. |
routes/frontend.php | none | web, contact guard, portal layout | frontend. |
routes/api.php | /api | api | api. |
routes/webhooks.php | /webhooks | webhooks - no session, cookies or CSRF | none |
Route::livewire('/myfeature', SyncOverview::class)
->name('myfeature.index')
->can('myfeature.manage');
Those four files are also where a Classic developer first feels the difference: Classic had one controller surface and you guarded it yourself. Put anything an outside service calls in routes/webhooks.php, not web.php. Those routes start no session, so each one verifies its own signature or token and sets its own throttle. Scheduled work goes in routes/console.php using Schedule::safeCommand() rather than Schedule::command(), so it still runs on servers that disable proc_open - which, on the shared hosting this platform targets, is most of them.
Extending other modules - the actual point
This is what Classic could not do, and it is why second-generation modules will feel built-in rather than bolted on.
| Need | Mechanism |
|---|---|
| Fields and filters on someone else’s resource | extendResource() |
| Relations, observers, access rules on their model | extendModel() |
| Columns and row actions on their table | extendTable() |
| Tabs, sections, actions on their page | page() |
| Free-form markup | slot() |
| Side effects | hooks and filters, listen() |
| Entries in types they expose | register() |
| Entries in a service they own | extend() |
register() is the one worth studying. Modules publish types that other modules add entries to - document types, web form types, AI features, billing parties, automation templates, privacy export providers, onboarding steps:
use Modules\Documents\DocumentType;
$module->register(fn (): DocumentType => DocumentType::make(
'work-order', 'wrench-screwdriver',
__('myfeature::app.work_order'), __('myfeature::app.work_orders'),
)->numbering('WO-'));
Wrapping it in a closure matters: the entry is skipped while the other module is disabled, instead of fataling at boot.
The requires mistake
module.json has a requires array for feature modules yours depends on. It is tempting to list everything you touch. Do not.
A module cannot be disabled while an enabled module lists it in
requires, or deleted while any installed module lists it, even a disabled one.
List Invoices, Projects and Tickets there and you have quietly taken away the customer’s ability to manage their own installation. They disable Tickets, Next refuses, and the reason is your module.
List only what you genuinely cannot run without. For everything else use whenEnabled() in the definition and Module::isEnabled() at runtime:
$module->whenEnabled('Tasks', fn (ModuleBuilder $module) => $module
->listen(TaskCompleted::class, MarkItemDone::class));
Core modules - Core, Permissions, Users, Auth, Contacts, Frontend, Billing, Signing, Ai, Automations, Integrations and the rest - ship with every install and are never listed in requires.
The same restraint applies to data. If your module stores rows that reference customers, invoices or projects, those references are the thing a future migration has to translate - which is exactly what makes Classic module data so expensive to move. Store a stable natural key alongside the foreign key and you will have saved your own customers a bad weekend.
Shipping
php artisan module:build MyFeature --with-vendor --force
Builds assets, runs the package checks, writes MyFeature-1.2.0.zip. Before you add any Composer dependency, add the documented replace block to the module’s composer.json, listing laravel/framework, the illuminate/* packages and livewire/livewire. Without it your vendor/ ships a second copy of the framework and validation rejects the upload.
Then bug_reports in module.json puts your module in the CRM’s bug-report form and sends reports to your endpoint, with diagnostics you define through $module->diagnostics(). It is the cheapest support channel you will ever set up, and it arrives with the PHP version, queue driver and recent errors already attached.
What to build first
Look at what Next absorbed before you plan anything. Automations, the shared inbox, PDF template design, deals, documents, web forms, the API, webhooks, MCP, AI, GDPR tooling, signing, Peppol e-invoicing and the Google, Meta and Microsoft integrations are all core now. The full before-and-after table is here - a lot of Classic module categories simply no longer exist as products.
What is still open: HR and payroll, inventory and purchasing, assets, appointments, accounting, ecommerce, custom data objects, country tax connectors outside Peppol and VeriFactu, SMS and WhatsApp, industry verticals and advanced reporting.
And one thing to check before you plan a multi-tenant product on top of it: the Next licence does not permit serving several businesses from one installation, or building a module for that.
Selling what you build is a separate problem with its own API - releases, verify and download endpoints you host yourself. That is covered here.
Common questions
How do I create a module for Perfex CRM Next?
Run php artisan module:make MyFeature with a --type profile: minimal, resource, settings, payment-gateway, integration or integration-api-key. It generates app/MyFeatureModule.php, a service provider, module.json, composer.json, routes, config and translations, and enables the module.
Can I port my Perfex Classic module to Next?
No, not as a port. Classic modules are CodeIgniter and Next modules are Laravel packages with a module definition class. They share no routing, ORM, templating, permission model or table layer, so every module is a rewrite.
What is the module definition class in Perfex CRM Next?
app/{Module}Module.php, extending ModuleDefinition. One define() method declares everything the module adds - permissions, menus, settings pages, widgets, resources, event listeners and extensions of other modules. It runs only while the module is enabled, so everything it declares disappears cleanly with the module.
Should I list other modules in the requires field of module.json?
Only when your module genuinely cannot function without them. A module cannot be disabled while an enabled module lists it in requires, so a careless entry stops the customer managing their own modules. Prefer whenEnabled() in the definition and Module::isEnabled() at runtime.
How does a Perfex CRM Next module extend another module?
Through the builder: extendResource() adds fields and filters, extendModel() adds relations and observers, extendTable() adds columns and actions, page() adds tabs and actions to another module page, slot() injects markup, and register() adds entries to types other modules expose.