untymage's avatar

IoC not auto resolving Too few argument...

web.php

$router->get('/updates',
    [
        'uses' => 'TelegramController@updates',
    ]
);

TelegramController.php


protected Api $tg;


public function __construct(Api $tg)
{
    $this->tg = $tg;

}

AppServiceProvider.php

$this->app
    ->when(TelegramController::class)
    ->needs(Api::class)
    ->give(function () {
        return new Api('TOKEN');
    });

When i hit the route :

Too few arguments to function App\Http\Controllers\TelegramController::__construct()

What i'm missing here?

0 likes
0 replies

Please or to participate in this conversation.