Skip to content

Getting started with modules ​

This guide sets up a local development environment, scaffolds a module with module:make, and shows how to enable and migrate it. It also covers the module layout, module.json, Composer autoloading, and the enable, disable and delete callbacks in bootstrap/module.php.

Configure your development environment ​

  1. Complete the regular installation on your local machine, including the database setup and admin account.

  2. From the application root, install development dependencies:

    bash
    composer install
  3. Edit the .env file created by the installer:

    dotenv
    APP_ENV=local
    APP_DEBUG=true

    Keep the existing application key and database settings. Update APP_URL if your local URL has changed.

  4. Clear the installation caches, and leave configuration uncached while working:

    bash
    php artisan optimize:clear --no-interaction

Scaffold ​

Create a module with php artisan module:make and a --type= profile:

bash
# Minimal module (default): shared infrastructure, extensions of other modules
php artisan module:make MyFeature

# Full CRUD module
php artisan module:make MyFeature Item --type=resource

# Settings module (admin settings dialog)
php artisan module:make MyFeature --type=settings

# Payment gateway driver module (registers with Billing)
php artisan module:make Stripe --type=payment-gateway
OptionPurpose
--type=Scaffold profile - see below. Defaults to minimal
--with-viteAdd vite.config.js, package.json, and asset entry files - see Public assets
--disabledDo not enable the module after creation
--forceDelete and recreate an existing module directory

The command enables the module and generates app/MyFeatureModule.php, the module definition where you declare menus, permissions and everything else the module adds.

Profiles ​

--type=GeneratesExamples
minimalapp/{Module}Module.php, service provider, module.json, composer.json, route files, config, translationsShared infrastructure, extensions of other modules
resourceEverything in minimal, plus a model, migration, factory, policy, Resource, list and record pages, create and edit forms, routes, menu entries and permissionsTickets, Expenses, Leads
settingsEverything in minimal, plus a settings dialog and its entry on the Settings page, gated by a {module}.manage permissionModule-specific settings
payment-gatewayEverything in minimal, plus an app/PaymentGateways/{Module}Gateway.php driver - see Payment gatewaysStripe, PayPal drivers
integrationEverything in minimal, plus an app/{Module}Integration.php that users connect their accounts to through the provider's OAuth 2 consent screen, registered in the module definition, with its app dialog in Settings → IntegrationsSlack, HubSpot, QuickBooks
integration-api-keyEverything in minimal, plus an app/{Module}Integration.php whose accounts the installation connects with an API key, registered in the module definition, with its accounts in Settings → IntegrationsMailchimp, SendGrid

The resource profile takes the model name as the second argument; when you omit it, the command offers the singular module name.

Generators ​

Add pieces to an existing module with the module-scoped generators:

bash
php artisan module:make-model Item MyFeature --no-interaction
php artisan module:make-migration create_items_table MyFeature --no-interaction
php artisan module:make-policy ItemPolicy MyFeature --no-interaction
php artisan module:make-core-resource Item MyFeature --no-interaction
php artisan make:livewire myfeature::my-settings --class --no-interaction

module:make-core-resource adds a Resource. Run php artisan list module for the full list.

Config ​

Every profile generates config/config.php. Menu entries read the module's icon from it with config('myfeature.icon'):

php
return [
    'name' => 'MyFeature',
    'icon' => 'cube',
];

Module layout ​

ConventionExample
Folder namePascalCase - Tickets, Billing
module.json aliaslowercase - tickets, billing
PHP namespaceModules\Tickets\...
View/lang prefixtickets::app.title
modules/MyFeature/
├── app/
│   ├── MyFeatureModule.php     # module definition: everything the module adds
│   ├── Providers/              # service provider
│   └── Livewire/, Models/, Policies/, Resources/, ...
├── bootstrap/module.php        # optional enable, disable and delete callbacks
├── config/config.php
├── database/migrations/
├── lang/en/app.php
├── public/                     # static files and built assets
├── resources/views/
├── routes/                     # admin.php, frontend.php, web.php, api.php, ...
├── tests/
├── composer.json
└── module.json

php artisan module:make creates this layout.

Core vs feature modules ​

Core modules ship with every installation, are always enabled, and cannot be disabled or deleted. They are Core, Permissions, Users, Auth, Contacts, Frontend, Billing, Signing, Ai, Automations, Integrations, OAuthServer, SupportConnect, Installer and Updater.

Feature modules are everything else under modules/ - e.g. Calendar, Tickets, Invoices, Companies, Leads, Deals, Tasks, Documents, Translator. Super-admins enable, disable, or delete them from Settings → System → Modules. Third-party modules distributed as ZIP files must pass packaging validation.

Separately sold add-ons can declare updates in module.json for in-app updates - see Updates and licensing.

Depending on other modules ​

  • Core modules - use them directly. Do not list them in requires.
  • Required feature modules - list them in module.json requires (see module.json) and use them directly.
  • Optional feature modules - see Optional modules.

Enable, disable, migrate ​

bash
php artisan module:list
php artisan module:enable MyFeature
php artisan module:disable MyFeature
php artisan module:migrate MyFeature
php artisan module:migrate-status MyFeature

WARNING

Always enable and disable via Artisan or Settings → System → Modules. Do not edit module status files manually.

module.json ​

json
{
    "name": "MyFeature",
    "alias": "myfeature",
    "requires": ["Companies"],
    "providers": [
        "Modules\\MyFeature\\Providers\\MyFeatureServiceProvider"
    ]
}

List only feature modules in requires, never core modules - see Core vs feature modules. Keep the service provider listed even when it is empty; it loads the module.

Composer autoload ​

oneCRM reads the autoload section of each module's own composer.json, so you never add module namespaces to the root composer.json. After changing that section, run php artisan core:flush-module-autoload --rebuild.

Third-party packages go in the module's own vendor/ directory, which is loaded automatically. Include it when you ship a ZIP - see Packaging and release.

Find your module's files with module_path('MyFeature', 'resources/data.json'), never a hard-coded modules/MyFeature: hosted installs can keep uploaded modules in a different folder.

Enable, disable and delete callbacks ​

An optional bootstrap/module.php registers callbacks for when the module is enabled, disabled, or deleted. Unlike the module definition, it also runs while the module is disabled:

php
use Illuminate\Contracts\Foundation\Application;
use Modules\Core\Facades\Module;

return Module::configure('myfeature')
    ->enabled(function (Application $app): void {
        //
    })
    ->disabled(function (Application $app): void {
        //
    })
    ->deleting(function (Application $app): void {
        //
    });

To run a callback for each of the named modules that is enabled, use whenEnabled() with one name or a list:

php
return Module::configure('myfeature')
    ->whenEnabled(['Tasks', 'Invoices'], function (Application $app, string $module): void {
        //
    });

Deleting a module rolls back its migrations. If your module stores references to another module's records, add cleanup for them - see Deleting a module.

When a user is deleted ​

Deleting a user hands their records to the user the admin picks. The creator and updater columns of models using HasUserStamps move without any code. Handle any other column pointing at users, such as an owner or a sales agent, in whenUserDeleting() in bootstrap/module.php:

php
use Modules\Core\Facades\Module;
use Modules\Deals\Models\Deal;
use Modules\Users\UserDeletion;

return Module::configure('deals')
    ->whenUserDeleting(fn (UserDeletion $deletion) => $deletion->reassign(Deal::class, 'user_id'));
MemberUse
$deletion->userThe user being deleted
$deletion->transferToThe user who receives their records
reassign($model, $column)Hands $model rows whose $column is the deleted user to transferTo
deleteOwned($model, $column)Deletes those rows instead, for private records such as personal templates

A nullable column that should be cleared instead uses nullOnDelete() on its foreign key.

What a module can extend ​

NeedMechanism
Pages, actions, tabs, sectionsPages
Free-form markup on pagesUI slots
Side effects (before/after events)Hooks and filters
Resource fields/filtersextendResource()
RelationshipsextendModel()
Tables, boards, listsTables, boards and lists, extendTable()
FormsForms
Notes, comments, filesFeatures
AutomationsAutomations
Calendar eventsAdmin integration
AI capabilitiesAI features
Online invoice paymentsPayment gateways
Entries in other modules' lists$module->register() - see Registrable types

Next steps ​

For any module:

  1. Declare menus and permissions in app/{Module}Module.php - see Module definition, Admin integration and Authorization
  2. Add routes, pages and Livewire components (make:livewire {module}::{name})
  3. Add translations in lang/en/app.php - see Translations
  4. Add the customer portal with $module->portal() and php artisan module:make-frontend-routes {Module} if customers use the module
  5. Add tests with module:make-test - see Testing
  6. Before shipping, read Packaging and release

For a resource module, also:

  1. Run php artisan module:migrate {Module}
  2. Add your fields and shape the index table in the Resource
  3. Adjust the policy only for extra abilities - see Policies

Giải pháp CRM Tinh gọn Tự lưu trữ - Sở hữu toàn quyền, không phụ phí định kỳ.