我已经在我的项目中使用了laravel 5.2。对于模块化方法,我在应用程序>模块以及用户>模块中都有模块。
模块服务提供程序>模块.php如下所示:
<?php namespace App'Modules;
use 'Illuminate'Support'ServiceProvider as ServiceProvider;
abstract class ModuleServiceProvider extends ServiceProvider{
public function boot() {
if ($module = $this->getModule(func_get_args())) {
$this->package("app/" . $module, $module, app_path() . "/modules/" . $module);
}
}
public function register() {
if ($module = $this->getModule(func_get_args())) {
$this->app["config"]->package("app/" . $module, app_path() . "/modules/" . $module . "/config");
// Add routes
$routes = app_path() . "/modules/" . $module . "/routes.php";
if (file_exists($routes))
require $routes;
}
}
public function getModule($args) {
$module = (isset($args[0]) and is_string($args[0])) ? $args[0] : null;
return $module;
}
}
?>
和我的领先服务提供商.php就像
<?php namespace App'Modules'Lead;
class LeadServiceProvider extends 'App'Modules'ModuleServiceProvider {
public function register()
{
parent::register("user");
}
public function boot()
{
parent::boot("user");
}
/**
* Register any application services.
*
* @return void
*/
}
我已经在我的应用程序中写了它.php提供者也是
喜欢
App''Modules''ModuleServiceProvider::class, App''Modules''Lead''LeadServiceProvider::class,
也是用 composer.json 编写的。
但它给出了这样的错误
ProviderRepository 中的 FatalErrorException .php第 146 行: 无法实例化抽象类应用程序''模块''模块服务提供程序
不能实例化抽象类。一个抽象类必须由另一个类扩展。但是,您的ModuleServiceProvider
似乎不包含任何抽象方法,因此它不需要是抽象的。从服务提供商中删除abstract
关键字,这应该可以解决问题。