I have the following codes:
Chat Staff Service
namespace Chat\Api\V1\Services\Chat;
class ChatStaffService extends Service
{
private $chatService;
public function __construct(ChatService $chatService)
{
$this->chatService = $chatService;
}
...
}
Chat Service
namespace Chat\Api\V1\Services\Chat;
class ChatService extends Service
{
private $chatStaffService;
public function __construct(ChatStaffService $chatStaffService)
{
$this->chatStaffService = $chatStaffService;
}
...
}
What's happening: In developing an API at some point I use ChatStaffService functions in ChatService and at other times I need to use ChatService functions in ChatStaffService. When I put dependency on any of the constructors the application simply stops and returns error 500. When I remove the dependency and try to use a function that does not need it everything returns to normal operation.
I need some idea to get around this problem. I tried to develop the following function to solve the problem but it did not work.
function checkAndInject($anInstance, $injection)
{
if($anInstance == true)
return $injection;
else
return \App::make($injection);
}