Skip to content

RouteGenerator ​

Class: Unusualify\Modularous\Generators\RouteGenerator
Source: src/Generators/RouteGenerator.php
Extends: Generator
Uses: ManageNames

The primary generator — invoked by modularous:make:route. Produces the complete set of PHP files for a new module route: config entry, model, migration(s), controllers, repository, form request, translation keys, and Spatie permissions.

Additional Properties ​

PropertyTypeDefaultDescription
$migratebooltrueRun modularous:migrate after generation
$migrationbooltrueGenerate a migration file
$plainboolfalseSkip file generation; only write the config entry
$typestring'web'Route type
$schemastring—Column definition string (e.g. title:string,body:text)
$rulesstring—Validation rules string (e.g. title=required|min:3)
$relationshipsstring—Pipe-separated relationship schemas
$useDefaultsbool—Include default columns (id, timestamps, etc.)
$customModelstring|null—Fully-qualified class name of an existing model to use instead of generating a new one
$traitsCollection[]Repository/model traits to apply
$tableNamestring|null—Override the auto-derived DB table name

generate() Flow ​

generate()
├── [test mode] runTest() → dry-run output, return 0
└── [normal mode]
    ├── updateConfigFile() or fixConfigFile()
    ├── addLanguageVariable()
    └── [not plain]
        ├── updateRoutesStatuses()    — enable route in module activator
        ├── generateFolders()         — create missing module directories
        ├── generateResources()       — model, migration, controllers, repo, request…
        ├── generateFiles()           — stub-based files (routes, Vue pages, etc.)
        ├── createRoutePermissions()  — Spatie permissions
        └── [migrate=true] modularous:migrate

After generation, runs composer run-script pint modules/{module} to auto-format the new files.

generateResources() ​

ResourceCommandCondition
Admin controllermodularous:make:controllerpaths.generator.route-controller enabled
API controllermodularous:make:controller:apipaths.generator.route-controller-api enabled
Front controllermodularous:make:controller:frontpaths.generator.route-controller-front enabled
Modelmodularous:make:modelAlways
Main migrationmodularous:make:migrationNo custom model — creates create_{table}_table
Add-columns migrationmodularous:make:migrationCustom model present — creates add_{table}_table
Extra pivot migrationsmodularous:make:migrationbelongsToMany relationships in schema
Extra morph migrationsmodularous:make:migrationmorphedByMany relationships in schema
Repositorymodularous:make:repositorypaths.generator.repository enabled
Form requestmodularous:make:requestpaths.generator.route-request enabled
API resourcemodule:make-resourcepaths.generator.route-resource enabled
Service providermodule:make-providerInteractive prompt (or unit test mode)
Middlewaremodule:make-middlewareInteractive prompt (or unit test mode)

updateConfigFile() ​

Builds the route entry and writes it to the module's Config/config.php:

php
$route_array = [
    'name'             => 'Post',
    'headline'         => 'Posts',
    'url'              => 'posts',
    'route_name'       => 'post',
    'icon'             => '$submodule',
    'title_column_key' => 'title',  // first 'name' or 'title' header, else first column
    'table_options'    => [
        'createOnModal' => true,
        'editOnModal'   => true,
        'isRowEditing'  => false,
        'rowActionsType'=> 'inline',
    ],
    'headers' => [...],   // from SchemaParser::getHeaderFormats()
    'inputs'  => [...],   // from SchemaParser::getInputFormats()
];

If the config file already exists, uses add_route_to_config(). Otherwise writes the full config via php_array_file_content().

fixConfigFile() ​

Called when $fix = true. Reads the existing config and merges the generated route array on top without overwriting manually set values. Preserves the existing name, headline, icon, table_options, headers, and inputs if already present.

addLanguageVariable() ​

Adds a translation entry to the modules group for every installed locale:

Key:   {module_snake}.{route_snake}.name
Value: "{Headline} | {Plural} | {n} {Plural}"

Example for a route named Post in module Blog:

blog.post.name = "Post | Posts | {n} Posts"

createRoutePermissions() ​

If Modules\SystemUser\Repositories\PermissionRepository exists, seeds the following Spatie permissions (guard = Modularous auth guard):

Permission suffixAbility
_createCreate records
_viewView/list records
_editEdit records
_deleteSoft-delete
_force-deletePermanent delete
_restoreRestore soft-deleted
_duplicateDuplicate a record
_reorderChange sort order
_bulkBulk operations
_bulk-deleteBulk soft-delete
_bulk-force-deleteBulk permanent delete
_bulk-restoreBulk restore

generateExtraMigrations() ​

Scans $relationships for pivot-table relationships and generates dedicated migration files:

Relationship typeMigration name
belongsToManycreate_{source}_{target}_table
morphedByManycreate_{morph_pivot_name}_table

Schema Format ​

php
// $schema — column definitions
$generator->setSchema('title:string,body:text,status:enum("draft","published")');

// $rules — validation rules
$generator->setRules('title=required|min:3|unique:posts,body=required');

// $relationships — pipe-separated
$generator->setRelationships('tags:belongsToMany|author:belongsTo');