Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nolros's avatar
Level 23

L5 Fresh - ServiceProvider Not Working?

My own ServiceProviders were working fine until I ported them across to a fresh install of L5. The composer is not loading and so I'm not getting any of my composer code.

// remove the rest for brevity
        'Illuminate\View\ViewServiceProvider',
        'Laravel\Socialite\SocialiteServiceProvider',
        'Illuminate\Html\HtmlServiceProvider',
        'Intervention\Image\ImageServiceProvider',


        /*
         * My own app SP
         */
        'App\Providers\TranslatorServiceProvider',

My SP

    /**
     * Registers the decorated translator
     *
     * @return void
     */
    public function register()
    {
        $this->registerLang();
        $this->registerAuthComposer();
    }


    /**
     * Register views to composer  
     */
    private function registerAuthComposer()
    {
        $this->app->view->composer('auth.register.start', TranslatorComposer::class );
        $this->app->view->composer('auth.login', TranslatorComposer::class );
    }


    /**
     * Register the service provider.
     *
     * @return void
     */
    private function registerLang()
    {

        $this->registerLoader();

        $this->app->singleton('translator', function($app)
        {
            $loader = $app['translation.loader'];

            $locale = $app['config']['app.locale'];

            $trans = new Translator($loader, $locale);

            $trans->setFallback($app['config']['app.fallback_locale']);

            return new TranslatorDecorator($trans, $app['config'], $this->app );

        });


    }

\\ excluding the 2 other Laravel methods

My Decorator class

class TranslatorDecorator extends TranslatorResource implements TranslatorInterface
{

    /**
     * Supported Locales
     *
     * @var array
     */
    protected $supportedLocales;

    /**
     * Current locale
     *
     * @var string
     */
    protected $currentLocale = false;

    /**
     * An array that contains all routes that should be translated
     *
     * @var array
     */
    protected $translatedRoutes = array();

    /**
     * Default locale
     *
     * @var string
     */
    protected $defaultLocale;

    /**
     * The actual translator instance
     * @var \Illuminate\Translation\Translator
     */
    protected $translator;
    /**
     * @var Repository
     */
    protected $configRepository;
    /**
     * @var Application
     */
    protected $app;

    /**
     * creates an instance of the decorator
     * @param TranslatorInterface $translator
     */
    public function __construct(TranslatorInterface $translator, Repository $configRepository,  Application $app )
    {
        $this->translator  = $translator;
        $this->configRepository = $configRepository;
        $this->defaultLocale = $this->configRepository->get('app.locale');
        $this->app = $app;
        $this->request = $this->app['request'];
    }

\\ lang methods below
0 likes
1 reply
nolros's avatar
Level 23

Ok, for some weird reason I had to do the following to get it to work:

1.  add boot() method to my SP
2. load View::composer with the Facade to get it to work.
3. Once it was working I once again ran clear compiled 
4. then removed all the boot code and went back to above and it works fine, which leads me to believe that the clear compiled needs to run on a working version of fresh version of L5 as it wont clear until the app runs once fine. weird 

Please or to participate in this conversation.