Helpers and Blade directive
This page lists the global functions in src/helpers.php, the @module Blade directive, and the php artisan about entry. Composer loads src/helpers.php via autoload.files.
Each function is defined only when no function of that name exists yet.
module()
Section titled “module()”module(string $name, bool $instance = false): bool|Nwidart\Modules\ModuleReturns the status of a module, or the module.
| Parameter | Description |
|---|---|
$name |
Module name. Matched like Module::find(): case-insensitive, and kebab-case and snake_case names find the studly-case module. |
$instance |
false: return the status. true: return the Module instance. |
Returns
| Case | Value |
|---|---|
$instance is false |
true when the module is enabled, otherwise false. |
$instance is true |
The Module. |
| The module does not exist | false, whatever $instance is. The function catches ModuleNotFoundException. |
if (module('Blog')) { // Blog exists and is enabled.}
$blog = module('Blog', true); // Module|falsemodule_path()
Section titled “module_path()”module_path(string $name, string $path = ''): stringReturns the folder of a module, or a path inside it.
| Parameter | Description |
|---|---|
$name |
Module name, matched like module(). |
$path |
Optional path inside the module. It is joined to the module folder with DIRECTORY_SEPARATOR. |
Returns the module folder without a trailing slash, followed by the separator and $path when $path is not empty.
Throws ModuleNotFoundException when the module does not exist.
module_path('Blog'); // /var/www/app/Modules/Blogmodule_path('Blog', 'routes/web.php'); // /var/www/app/Modules/Blog/routes/web.phpmodule_vite()
Section titled “module_vite()”module_vite(string $module, string $asset, ?string $hotFilePath = null): Illuminate\Foundation\ViteReturns a copy of the application Vite instance, set up for the build of one module. The shared instance that @vite uses stays unchanged.
| Parameter | Description |
|---|---|
$module |
Build directory, passed to useBuildDirectory(). The generated layout passes build-<lowername>. |
$asset |
The entry point, passed to withEntryPoints(). |
$hotFilePath |
Hot file passed to useHotFile(). Defaults to storage_path('vite.hot'). Generated layouts pass storage_path('vite-<lowername>.hot'), matching hotFile in the module vite.config.js. |
Returns the configured Vite instance. Printing it in a Blade view ({{ module_vite(...) }}) outputs the tags.
{{ module_vite('build-blog', 'resources/assets/js/app.js') }}{{ module_vite('build-blog', 'resources/assets/js/app.js', storage_path('vite-blog.hot')) }}The first call reads storage/vite.hot. The second reads the hot file that npm run dev writes in a module generated by the current stubs. See Build a module on its own.
The build-<lowername> directory holds the standalone build of a module. A build from the application root with vite-module-loader.js writes to public/build, which @vite reads.
config_path()
Section titled “config_path()”Deprecated Lumen compatibility shim, removed in version 14. Laravel defines config_path() itself.
config_path(string $path = ''): stringReturns the application config folder, or a path inside it. Defined only when no config_path() function exists yet.
| Parameter | Description |
|---|---|
$path |
Optional path inside the config folder. Joined with DIRECTORY_SEPARATOR as given. |
Returns <base path>/config, followed by the separator and $path when $path is not empty.
config_path('blog.php'); // /var/www/app/config/blog.phppublic_path()
Section titled “public_path()”Deprecated Lumen compatibility shim, removed in version 14. Laravel defines public_path() itself.
public_path(string $path = ''): stringReturns the application public folder, or a path inside it. Defined only when no public_path() function exists yet.
| Parameter | Description |
|---|---|
$path |
Optional path inside the public folder. Leading separators are stripped before joining with DIRECTORY_SEPARATOR. |
Returns the path.public binding, followed by the separator and $path when $path is not empty.
public_path('modules/blog'); // /var/www/app/public/modules/blog@module
Section titled “@module”LaravelModulesServiceProvider::boot() registers the directive via callAfterResolving('blade.compiler') using $blade->if('module', ...), so booting does not eagerly resolve Blade. The condition is module($name): true when the module exists and is enabled. Supports @else, @elseif, and @endmodule.
@module('Blog') <a href="{{ route('blog.index') }}">Blog</a>@endmodulephp artisan about
Section titled “php artisan about”When running in the console, LaravelModulesServiceProvider::boot() adds a section to the about command.
| Section | Entry | Value |
|---|---|---|
Laravel-Modules |
Version |
The installed version of nwidart/laravel-modules, from Composer. |
php artisan about