I have an issue with Laravel (version is 10.10). I have created a singleton in AppServiceProvider.php:
public function register(): void
{
$this->app->singleton('customService', \App\Services\CustomService::class);
}
I have a function in a controller just like that:
public function test()
{
$state = app('customService')->func('test', 'test');
$items = app('customService')->getRecents();
return ['items' => $items];
}
The problem is that every time the function is called, it should return me the first initialized instance of the singleton without creating new ones (d'uh), but instead it creates a new instance every time the controller methods is called.
The interesting thing is that when I try to run the same functions of the customService using Laravel Tinker, the instance is persisted and no new instances are replacing the current one (how it should be).
Can anyone please explain what am I missing here?