Filipe Ferminiano Filipe Ferminiano - 21 days ago 14
PHP Question

Call to undefined method from composer added package

I'm trying to use SlackBot class with my Laravel 5 app.

But I'm getting this error:

Call to undefined method Mpociot\SlackBot\Facades\SlackBot::initialize()


This is my controller:

use SlackBot;

public function slack_bot()
{

$slackbot = new SlackBot();
$slackbot->initialize('xoxb-XXX');

}


I tried to debug which methods are available with this:

$methods = get_class_methods($slackbot);
print_r($methods);


and I got this:

Array ( [0] => swap [1] => shouldReceive [2] => getFacadeRoot [3] => clearResolvedInstance [4] => clearResolvedInstances [5] => getFacadeApplication [6] => setFacadeApplication [7] => __callStatic )


which is very different from the methods defined in github class]2.

How can I fix this?




What I have done:

I'm following this tutorial

I ran composer require mpociot/slackbot

And then I added to config/app.php the service provider:

Mpociot\SlackBot\SlackBotServiceProvider::class,


and the alias / facade:

'SlackBot' => Mpociot\SlackBot\Facades\SlackBot::class

Answer

You're getting a instance of the Facade instead of the real class.

Replace your

    $slackbot = new SlackBot();
    $slackbot->initialize('xoxb-XXX');

With:

    $slackbot = SlackBot::initialize('token');
Comments