dongshi3061 2015-03-09 04:13
浏览 60

Laravel 5 - 多个自定义服务提供商

I've created a service provider called \App\Providers\HelperServiceProvider.php with this content:

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Session;
use View;

class HelperServiceProvider extends ServiceProvider {

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        foreach (glob(app_path().'/Helpers/*.php') as $filename){
            require_once($filename);
        }
    }

}

And also included in providers in \config\app.php

This works fine until recently I wanted to add a new provider for different purposes. So I created a new one App\Providers\ComposerServiceProvider.php

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Session;
use View;

class ComposerServiceProvider extends ServiceProvider {

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        # This content doesn't really matter. It still doesn't work even if I remove it.
        # View composer for partials.alert
        # Some code
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
    }

}

And included in the config too so it looks like this:

<?php   
        /* ^Some other things
         *
         * Application Service Providers...
         */
        'App\Providers\AppServiceProvider',
        'App\Providers\BusServiceProvider',
        'App\Providers\ConfigServiceProvider',
        'App\Providers\EventServiceProvider',
        'App\Providers\RouteServiceProvider',
        'App\Providers\HelperServiceProvider',
        'App\Providers\ComposerServiceProvider',

But it came out as Internal Server Error. It works fine when I take out from the providers config. I've tried everything I can think of. I tried removing everything inside boot(), changing the order of the providers, renaming the providers, but none of them worked. I can't get to the php/apache log file for other technical reason. Is there any problem with this implementation that I missed?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装