1
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 is going on: In the development of an API at a certain time I use Chatstaffservice functions in Chatservice and at other times I need to use Chatservice functions in Chatstaffservice. When I put the dependency on any of the constructors the application simply stops and turns error 500. When I remove the dependency and try to use a function that does not need it everything goes back to function normally.
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);
}
Can put
namespace
and because you need to use one inside the other, I believe the problem lies in this aspect– novic
I added the namespace
– Marcus Vinicius Campos
https://laravel.com/docs/5.2/providers have you already done this? or/e que http://answall.com/questions/116115/como-o-laravel-5-faz-para-que-uma-inst%C3%A2ncia-seja-passada-automaticamente-se-Ape/116213#116213, ie, already registered these classes for the Laravel to climb?
– novic
Yes yes, I’ve done it, the same thing happens. I’m thinking about making a super class and abstract the functionalities. But I wanted a more elegant solution than this.
– Marcus Vinicius Campos
Look, it’s hard to know why there’s a $500 error without seeing the whole code. Making a class does not guarantee that it will solve your problem, maybe remedy this error, but, you must find the why of this, what you did to make it happen ...
– novic
The problem is that the application does not return absolutely anything, not even in log. I tried everything, only gives error 500.
– Marcus Vinicius Campos
Because there are errors in coding, Laravel only works with the whole set of classes are working properly, if it has missing a comma does not rotate...
– novic
The problem is that the 2 services have been running for almost a year without any problems. The only thing I’ve done now is to inject when it stopped working.
– Marcus Vinicius Campos
It can be through internal programming, it can be through a call to another and it is violating something, it is so many things that it is difficult without seeing
– novic