I am using Laravel Lumen (v8.2.4) with PHP (v7.4) I have the following controller class:
<?php
namespace App\Http\Controllers;
use App\Services\MyService;
class MyController extends Controller
{
protected $myService;
public function __construct(MyService $myService)
{
$this->myService = $myService;
}
}
And the following service class:
<?php
namespace App\Services;
class MyService
{
private $credentials;
function __construct($credentials)
{
$this->credentials = $credentials;
}
}
The myService class requires the credentials property to be set in order to function correctly. When myService is being injected into my controller class, I don't have the credentials at that time so therefore cannot initialise the service class to inject it.
How can I handle this? Should I remove the service class constructor and set the credentials property in a public setter method and invoke this when I need to? I am not sure if this is a good approach.
Appreciate any advice.