There are multiple packages available for creating modules
Example https://nwidart.com/laravel-modules/v6/basic-usage/creating-a-module
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
HI..,I'm new to Laravel i want create module Can anyone suggest how to do it?
Thank you in advance
There are multiple packages available for creating modules
Example https://nwidart.com/laravel-modules/v6/basic-usage/creating-a-module
@sinnbeck Thank you for replying ., I tired to follow the above steps and i am stuck at this error
Error Class 'Modules\Blog\Providers\Blog ServiceProvider' not found at
C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:208 204▕ * @return \Illuminate\Support\ServiceProvider 205▕ */ 206▕ public function createProvider($provider) 207▕ { ➜ 208▕ return new $provider($this->app); 209▕ } 210▕ } 211▕ 1 C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:144
Illuminate\Foundation\ProviderRepository::createProvider("Modules\Blog\Providers\BlogServiceProvider") 2 C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:61 Illuminate\Foundation\ProviderRepository::compileManifest() Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Did you make a new service provider with a space in the name? Blog ServiceProvider
@Sinnbeck NO I have created a provider called BlogServiceProvider
@neetha_hm Well if you look at the error, there is clearly a space in the name? Can you perhaps share the error page (there is a share button)
@Sinnbeck i am not able to link any picture here because i have signed up today
Error
Class 'Modules\Blog\Providers\BlogServiceProvider' not found
at C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:208 204▕ * @return \Illuminate\Support\ServiceProvider 205▕ */ 206▕ public function createProvider($provider) 207▕ { ➜ 208▕ return new $provider($this->app); 209▕ } 210▕ } 211▕
1 C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:144 Illuminate\Foundation\ProviderRepository::createProvider("Modules\Blog\Providers\BlogServiceProvider")
2 C:\xampp\htdocs\extra\laravelModule\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:61 Illuminate\Foundation\ProviderRepository::compileManifest()
-----this is the complete error i am getting in Terminal when i run the below command
php artisan vendor:publish --provider=ogDatabaseSeeder.php"Nwidart\Modules\LaravelModulesServiceProvider
@neetha_hm Ok better error :) Check if you have a file at modules/Blog/Providers/BlogServiceProvider.php
@Sinnbeck yes..,i have that file
@neetha_hm Did you update your autoloader section in composer.json?
https://nwidart.com/laravel-modules/v6/installation-and-setup
@Sinnbeck i executed the composer dump-autoload but got same error again
@neetha_hm Can you show your composer.json ?
@Sinnbeck This is the path C:\xampp\htdocs\extra\laravelModule\Modules\Blog\composer.json
{ "name": "nwidart/blog", "description": "", "authors": [ { "name": "Nicolas Widart", "email": "[email protected]" } ], "extra": { "laravel": { "providers": [], "aliases": {
}
}
},
"autoload": {
"psr-4": {
"App\": "app/",
"Modules\": "Modules/"
}
}
}
@neetha_hm Ah ok so the actual path on your computer is Modules/Blog/Providers/BlogServiceProvider.php not modules/Blog/Providers/BlogServiceProvider.php. Correct ?
@Sinnbeck Yes.
@neetha_hm Can you post the BlogServiceProvider.php ?
@Sinnbeck namespace Modules\Blog\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Database\Eloquent\Factory;
class BlogServiceProvider extends ServiceProvider { /** * @var string $moduleName */ protected $moduleName = 'Blog';
/**
* @var string $moduleNameLower
*/
protected $moduleNameLower = 'blog';
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations'));
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);
}
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'),
], 'config');
$this->mergeConfigFrom(
module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower
);
}
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'Resources/views');
$this->publishes([
$sourcePath => $viewPath
], ['views', $this->moduleNameLower . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
}
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower);
}
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (\Config::get('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
return $paths;
}
}
@neetha_hm It seems that you did everything correctly, so I am unsure why php cant detect that class. Without having the code I am currently at a loss.
@Sinnbeck hey.., This is the link to the github https://github.com/neetha-hm/LaravelModuleFinal.git
@neetha_hm You never added the modules to the main autoloader here
https://github.com/neetha-hm/LaravelModuleFinal/blob/main/composer.json#L26
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/",
"Modules\": "Modules/"
}
},
@Sinnbeck Thank you for your help :).Now its working fine
@neetha_hm Great :)
@neetha_hm I think this package gonna help you : https://pharaonic.io/packages/laravel/modulator
@Pharaonic This link is not working
Please or to participate in this conversation.