laravel-notification-channels / telegram

✈️ Telegram Notifications Channel for Laravel
https://laravel-notification-channels.com/telegram/
MIT License
963 stars 162 forks source link

Problem with lumen 8 - call to a member function resolved on null #158

Open sopheary opened 1 year ago

sopheary commented 1 year ago

[2022-10-22 07:01:30] local.ERROR: Call to a member function resolved() on null {"exception":"[object] (Error(code: 0): Call to a member function resolved() on null at D:\sopheary_project\email_service\vendor\illuminate\support\Facades\Facade.php:36) [stacktrace]

0 D:\sopheary_project\email_service\vendor\laravel-notification-channels\telegram\src\TelegramServiceProvider.php(32): Illuminate\Support\Facades\Facade::resolved(Object(Closure))

1 D:\sopheary_project\email_service\vendor\laravel\lumen-framework\src\Application.php(233): NotificationChannels\Telegram\TelegramServiceProvider->register()

2 D:\sopheary_project\email_service\bootstrap\app.php(29): Laravel\Lumen\Application->register(Object(NotificationChannels\Telegram\TelegramServiceProvider))

3 D:\sopheary_project\email_service\public\index.php(14): require('D:\\sopheary_pro...')

4 {main}

"}

irazasyed commented 1 year ago

Lumen doesn't support notifications out of the box. You need to set it up.

Install the illuminate/notifications package and then follow the instructions given here.

Please update this issue ticket once you try.

sopheary commented 1 year ago

Thank you for your reply. I already installed "illuminate/notifications": "^8.83" before I got the above error.

NextStepOfEvolution commented 6 months ago

Solve this error by edit TelegramServiceProvider.php

<?php 
namespace NotificationChannels\Telegram;

use Closure;
use GuzzleHttp\Client as HttpClient;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;

/**
 * Class TelegramServiceProvider.
 */
class TelegramServiceProvider extends ServiceProvider
{
    /**
     * Register the application services.
     */
    public function register(): void
    {
        $this->app->bind(Telegram::class, static fn () => new Telegram(
            config('services.telegram-bot-api.token'),
            app(HttpClient::class),
            config('services.telegram-bot-api.base_uri')
        ));
    }
    public function booted(Closure $callback)
    {
        Notification::resolved(static function (ChannelManager $service) {
            $service->extend('telegram', static fn ($app) => $app->make(TelegramChannel::class));
        });
    }
}