Search code examples
laravelbindingservice-provider

Laravel bindings - how to use call() method?


Could you give some example of usage of Laravel binding call() method? Below you have Laravel Container Interface call() method.

/**
* Call the given Closure / class@method and inject its dependencies.
*
* @param  callable|string  $callback
* @param  array  $parameters
* @param  string|null  $defaultMethod
* @return mixed
*/
public function call($callback, array $parameters = [], $defaultMethod = null);

I guess to work with that this way:

$this->app->call('how_to_use_this_params')

Thanks in advance.


Solution

  • I found this years after...

    Thanks for putting me on the path to find what i wanted and my guessing was true!

    This is to make a call to an object method using dependency injection.

    like:

    class ...{
         public function methodName(Request $request){
             ...
         }
    }
    // this call will resolve the $request by IOC
    app()->call([$object,'methodName']);