Support the ongoing development of →
posted 8 years ago
Last updated 2 years ago.

Ok, so changing the service provider like so:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use App\Support\UserMessage\UserMessage;
use App\Contracts\UserMessageContract;

class UserMessageProvider extends ServiceProvider
    protected $defer = true;

    public function register()
        $this->app->singleton(UserMessageContract::class, function ($app)
            return new UserMessage();

        $this->app->alias(UserMessageContract::class, 'usermessage');

    public function provides()
        return [UserMessageContract::class, 'usermessage'];

gives the desired result. The class gets resolved out of the IoC container and I can still use the alias, i.e app('usermessage');

Last updated 8 years ago.

Sign in to participate in this thread!


Your banner here too?

john052 john052 Joined 26 May 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.