Laravel fails to resolve the dependencies of a class when instantiating with parameters.
Does the current implementation only support having those parameters passed to the closure when binding an interface or alias in e.g. a service provider or should the framework pass them to the constructor of the class and is this a bug? I remember there being a paramount distinction in the use of this method.
laravel new directory<?php
namespace App;
class ApiService
{
/**
* @var string
*/
public $clientId;
/**
* @param string $clientId
*/
public function __construct(string $clientId)
{
$this->clientId = $clientId;
}
}
boot method in AppServiceProvider (to test in the CLI):public function boot()
{
app(ApiService::class, ['id']);
// or
app()->makeWith(ApiService::class, ['id']);
}
This is intentional, you need to pass the parameter name:
app()->makeWith(ApiService::class, ['clientId' => 'id']);
That seems odd, but ok :p If a parameter is missing, does the container auto-resolve it if type-hinted?
Most helpful comment
This is intentional, you need to pass the parameter name: