Ad
Pass Param To Construct
I write a class like that:
class SERVICE
{
public function __construct($a, UserRepository $repository) {
$this->repository = $repository; $this->relations = [
[
'\Api\Users\Models\Client', 'clients', '$a'
]
];
$this->events = [ ];
}
...
}
and i used those class like that:
use SERVICE;
class TEST
{
public function __construct(SERVICE $service)
{
$this->service = $service;
}
}
and i have error:
Unresolvable dependency resolving [Parameter #0 [ $a ]]
how can I sen parameter in this way?
Ad
Answer
Laravel automatically can inject only https://laravel.com/docs/5.5/container#automatic-injection. For you case in service has $a
parameter which type is not defined. You must be change or your service __construct, or Test
class. For example
use SERVICE;
class TEST
{
public function __construct(UserRepository $repository) {
$this->service = new Service('some-value', $repository);
}
}
Or change service like this
class SERVICE
{
public function __construct(UserRepository $repository) {
$this->repository = $repository;
$this->events = [ ];
}
public function setRelations($a)
{
$this->relations = [
[
'\Api\Users\Models\Client', 'clients', '$a'
]
];
}
...
}
And usage
use SERVICE;
class TEST
{
public function __construct(SERVICE $service)
{
$this->service = $service;
$this->service->setRelations('some-value');
}
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad