Trying to add a constructor function to one my controllers. However, I am getting this error before I’ve even had a chance to instantiate the class in the my blade file.
Uncaught Exception: Unresolvable dependency resolving [Parameter #0 [ <required> string $post_id ]] in class App\Controllers\Translate
Here’s my construct:
function __construct(string $post_id, string $target_language)
{
$this->post_id = $post_id;
$this->target_language = $target_language;
}
Here’s the exception from Container.php:
/**
* Throw an exception for an unresolvable primitive.
*
* @param \ReflectionParameter $parameter
* @return void
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function unresolvablePrimitive(ReflectionParameter $parameter)
{
$message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";
throw new BindingResolutionException($message);
}
Any idea what could be causing this? Are we not suppose to add constructors in controllers?
Note: I am using v. 2.1.0. I didn’t see any older issues that would make me think upgrading would resolve this.