Tuesday, February 28, 2017

How to apply params for contextual binding interface resolving in laravel 5

I want to resolve context binding with parameters like this:

$this->app->when(ParticipantAddedToWaitingList::class)
            ->needs(NotificationParamsResolverInterface::class)
            ->give(function ($event_id, $params = []) {
                return new EventNotificationParamsResolver($event_id, $params);
            });

by using this:

app()->make(NotificationParamsResolverInterface::class, [123, [1,2,3]]);

is this possible or how could I achieve this ?

I know that contextual binding is only resolveable from constructor which does not allows to put params, am I right ?

Is there any workaround for that ?




via Rafał Łyczkowski

Advertisement