Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Nutaram does not get Laravel Cache system by default. #379

Closed
dnl4 opened this issue Mar 9, 2023 · 2 comments
Closed

[BUG] Nutaram does not get Laravel Cache system by default. #379

dnl4 opened this issue Mar 9, 2023 · 2 comments

Comments

@dnl4
Copy link

dnl4 commented Mar 9, 2023

Nutgram version

3.16.0

Describe the bug

I'm using laravel 9. The cache wasn't working so I wasn't able to use Conversations.

In the documentation it says that if you use laravel, you don't need to do anything for the cache to work.

I'm suspecting that in versions prior to laravel 9 the file config/nutgram.php could detect the laravel cache. But in Laravel 9, it can't.

I managed to solve this problem using the following code directly in the controller:

$bot = new Nutgram(env('TELEGRAM_TOKEN'), [
    'cache' => \Cache::store('redis'),
]);

But if I try to implement it as a default setting in config/telegram.php, I got a error:

'config' => [
    'cache' => \Cache::store('redis'),
],

Generates the error:

Class "Cache" not found

To Reproduce

  1. Install laravel 9
  2. Install nutgram
  3. Modify config/nutgram.php 'config' attribute to use 'cache' => \Cache::store('redis'),

Expected behavior

Cache everything

Screenshots

No response

Additional context

No response

@sergix44
Copy link
Member

sergix44 commented Mar 11, 2023

I'm not able to reproduce the issue, I've several bots with Laravel 9 and works just fine.

You should not define the cache store inside the config.php, because at a config resolution time the service container is not yet booted, thats why you are getting an error. The cacherepository is automatically resolved by the service provider (https://github.com/nutgram/nutgram/blob/master/src/NutgramServiceProvider.php#L56) as long you define a default cache driver in the laravel config.

@dnl4
Copy link
Author

dnl4 commented Mar 14, 2023

I've messed up.

I was using a controller to receive the webhook updated instead of __invoke() the bot. So all my handlers was in that controller. When I moved my handlers to routes/telegram.php and used __invoke() to run the bot, as the documentation states, all worked just fine.I don't know if you want to do anything with this information, so I will leave the issue opened, but feel free to close it.

@sergix44 sergix44 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants