How to echo the name of a 'module' in my laravel app?

by elise_daugherty , in category: PHP General , 9 months ago

How to echo the name of a 'module' in my laravel app?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 9 months ago

@elise_daugherty 

To echo the name of a module in your Laravel app, you can use the config helper function to retrieve the value of the module's configuration file.


First, make sure you have created a configuration file for your module. If you haven't, create a file named module.php in the config directory of your module's folder. In this file, define the configuration option for the module's name:

1
2
3
4
5
// config/module.php

return [
    'name' => 'YourModuleName',
];


Next, you need to register the module's configuration file with Laravel. Open the config/app.php file, and add the path to your module's configuration file to the config array:

1
2
3
4
5
6
// config/app.php

'config' => [
    // ...
    'your-module' => config_path('module.php'),
],


Now, you can use the config helper function to retrieve the value of the module's name:

1
echo config('your-module.name');


This will echo the name of your module, which you defined in the module.php configuration file.