CasperLaiTW / laravel-fb-messenger

Laravel Facebook Messenger Provider
MIT License
105 stars 27 forks source link

Cannot declare class Menu, because the name is already in use #75

Closed joelcuevas closed 7 years ago

joelcuevas commented 7 years ago

I'm getting this error on v1.4.1:

ErrorException: Cannot declare class Menu, because the name is already in use

The line responsible:

/vendor/casperlaitw/laravel-fb-messenger/src/Providers/MenuServiceProvider.php:21

Didn't test further, but this could be happening on v1.4.0 too.

CasperLaiTW commented 7 years ago

Hi @joelcuevas

Please upgrade to v1.4.2

I remove the auto alias, and you have to add alias to config by yourself.

You can name another alias name for Menu.

Example:

'alias => [
    ...
    'PerisistentMenu' => Casperlaitw\LaravelFbMessenger\Facades\MessengerMenu::class,
    ...
],

In menu.php

use Casperlaitw\LaravelFbMessenger\Messages\UrlButton;

// default locale must be required.
PerisistentMenu::locale('default', function () {
   PerisistentMenu::postback('Test Button', 'TEST_POSTBACK');
   PerisistentMenu::webUrl('WebUrl', 'https://github.com/CasperLaiTW/laravel-fb-messenger');

   PerisistentMenu::nested('SubMenu', function () {
      PerisistentMenu::postback('SubMenu-Button', 'TEST_SUB_BUTTON');
      PerisistentMenu::webUrl(new UrlButton('SubMenu-WebUrl', 'https://github.com/CasperLaiTW/laravel-fb-messenger'));
   });
});