module ​
File: src/Helpers/module.php
Module context, configuration, permission, and debug helpers. This is the largest helper file for module-aware code — used heavily in service providers, console commands, and module config files.
Module Context ​
Functions that resolve the "current module" by tracing the PHP call stack.
modularousBaseKey ​
modularousBaseKey(string $notation = null): stringReturns the root config key for Modularous (default: modularous). If MODULAROUS_BASE_NAME is set in .env, it is used instead. Optional $notation is appended with a . separator.
modularousBaseKey('locale'); // → 'modularous.locale'curtModule ​
curtModule(string $file = null): ModuleResolves and returns the current module instance by tracing the file path in the call stack to extract a module name, then calling Modularous::find().
curtModuleName ​
curtModuleName(string $file = null): stringExtracts the module name from the call stack by matching the Modules/{ModuleName} pattern. Throws ModularousException if it cannot be determined.
curtModuleUrlPrefix / curtModuleRouteNamePrefix ​
curtModuleUrlPrefix(string $file = null): string
curtModuleRouteNamePrefix(string $file = null): stringReturns the URL prefix / route name prefix of the current module.
curtModuleStudlyName / curtModuleLowerName / curtModuleSnakeName ​
curtModuleStudlyName(string $file = null): string
curtModuleLowerName(string $file = null): string
curtModuleSnakeName(string $file = null): stringReturn the current module name in the requested casing.
Trait / Class Inspection ​
classUsesDeep ​
classUsesDeep(mixed $class, bool $autoload = true): arrayReturns all traits used by a class and all of its parent classes — including traits used by other traits (recursive). Returns a flat, unique array of trait names.
classHasTrait ​
classHasTrait(mixed $class, string $trait): boolReturns true if $class (or any parent/trait in the hierarchy) uses $trait. Uses classUsesDeep internally.
Route Helpers ​
moduleRoute ​
moduleRoute(
string $moduleName,
string $prefix,
string $action = '',
array $parameters = [],
bool $absolute = true,
bool $singleton = false
): stringGenerates a full URL for a module route. Automatically appends :id for edit/show/update/destroy/duplicate actions on non-singleton resources. Throws ModularousException with full context on route generation failure.
modularousRoute ​
modularousRoute(
string $route,
string $prefix,
string $action = '',
array $parameters = [],
bool $absolute = true
): stringSimilar to moduleRoute but for Modularous built-in routes (not module-specific).
Trait Options ​
getModularousTraits / activeModularousTraits / modularousTraitOptions ​
getModularousTraits(): array
activeModularousTraits(array $traitOptions): Collection
modularousTraitOptions(bool $asSignature = false): array|stringRead the registered trait list from modularous.traits config. modularousTraitOptions can return either a plain array or a formatted Symfony InputOption signature string for make:* commands.
Configuration ​
modularousConfig ​
modularousConfig(string $notation = null, mixed $default = ''): mixedShorthand for config(modularousBaseKey($notation), $default). The most-used helper across the entire codebase.
Permissions ​
formatPermissionName ​
formatPermissionName(string $routeName, string $permissionType): stringReturns a kebab-cased permission name: route-name_permission-type.
formatPermissionRecord ​
formatPermissionRecord(string $routeName, string $permissionType, string $guardName): arrayReturns ['name' => ..., 'guard_name' => ...] for a Spatie Permission record.
routePermissionRecords ​
routePermissionRecords(string $routeName, string $guardName, array $cases = null): arrayReturns all permission records for a route across all Permission enum cases.
permissionRecordsFromRoutes ​
permissionRecordsFromRoutes(array $routes, string $guardName): arrayReturns permission records for multiple routes combined.
Debug / Utility ​
ifdd ​
ifdd(bool $condition, mixed ...$vars): voidConditional dd(). Dumps all $vars and exits only if $condition is true. Uses VarDumper::dump directly.
exceptionalRunningInConsole ​
exceptionalRunningInConsole(): boolReturns true if the app is NOT running specific module-generation console commands. Used to skip expensive boot steps when running make:module, make:route, etc.
backtrace_formatter / backtrace_formatted ​
backtrace_formatter(array $carry, array $item): array
backtrace_formatted(): arraybacktrace_formatted() returns a clean associative array of the current call stack: ['file' => ['line' => N, 'function' => 'fn']].
benchmark ​
benchmark(
callable $callback,
string $label = null,
bool $die = false,
string $unit = 'milliseconds',
string &$elapsedString = null
): mixedWraps $callback with timing. Logs to the modularous-benchmark channel:
- At
emergencylevel if elapsed exceedsbenchmark_emergency_timeconfig (default 1000ms) - At
debuglevel ifbenchmark_log_levelis'debug'
Set $die = true to throw immediately with the elapsed time (useful for profiling in development). Set $label to identify the operation in logs. Only active when benchmark_enabled config is true.
mergeConfigFrom ​
mergeConfigFrom(string $path, string $key): voidLoads a PHP config file from $path and deep-merges it (via array_merge_recursive_preserve) into the existing $key config value. Overrides Laravel's default mergeConfigFrom which uses a shallow array_merge.
findParentRoute ​
findParentRoute(array $config): arrayReturns the first route in a module config that has 'parent' => true.