laravel 5.2 中的立面错误

Facade error in laravel 5.2

我在 Laravel 5.2 安装了一个名为 jonnywilliamson/laragram

的包

并输入 config\app.php 别名和服务提供商,如下所示:

 'providers' => [
    .
    .
    .,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    Williamson\Laragram\Laravel\LaragramServiceProvider::class,
 ]


 'aliases' => [
    .
    .
    .,
    'URL' => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View' => Illuminate\Support\Facades\View::class,
    'TG' => Williamson\Laragram\Laravel\LaragramFacade::class,
 ]

在我的控制器中:

 use TG;

 public function test()
 {
  return TG::sendMsg('+989118000000', 'Hello there!');
 }

和路线:

Route::get('test', 'Services\Auth\Controller\v1_0\AuthController@test');

我还运行以下命令:

   composer dumpautoload 
   composer dumpautoload -o 
   php artisan cache:clear 
   php artisan clear-compiled
   php artisan optimize

但仍然显示如下错误:

 RuntimeException in Facade.php line 210:
 A facade root has not been set.
 in Facade.php line 210

 at Facade::__callStatic('sendMsg', array('+989118000217', 'Hello there!')) in User.php line 68
 at LaragramFacade::sendMsg('+989118000217', 'Hello there!') in User.php line 68
 at AuthController->test('fa')
 at call_user_func_array(array(object(AuthController), 'test'), array('lang' => 'fa')) in Controller.php line 80
 at Controller->callAction('test', array('lang' => 'fa')) in ControllerDispatcher.php line 146
 at ControllerDispatcher->call(object(AuthController), object(Route), 'test') in ControllerDispatcher.php line 94
 at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))

我该如何解决?

您尝试调用的函数名为 sendMessage:

return TG::sendMessage('+989118000000', 'Hello there!');

您正在使用 sendMsg,这是导致错误的原因。