找不到“Pusher”类

时间:2017-07-12 08:50:35

标签: laravel-5 pusher

当我安装Pusher包时,我收到错误“Class'Pusher'not found'。

4 个答案:

答案 0 :(得分:26)

Claudio的诊断是正确的,在版本3中添加了名称空间Pusher;但是不推荐更改Laravel文件。

更好的方法是在maxBikes = Math.max.apply(null, arr.map((x) => x.one.details.bikes)) maxCars = Math.max.apply(null, arr.map((x) => x.one.details.cars)) 中创建别名。根据'别名'键,将其添加到"第三方别名"中的数组中。部分:

config/app.php

答案 1 :(得分:1)

(OP在问题中发布了以下答案。基本问题是pusher-php-server的第3版引入了命名空间,因此现在需要use Pusher\Pusher。)

创建此命令:

namespace App\Console\Commands;

use Illuminate\Support\Facades\File;
use Illuminate\Console\Command;

class FixPusher extends Command
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fix:pusher';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Fix Pusher namespace issue';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $broadcastManagerPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php');
        $pusherBroadcasterPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php');

        $contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($broadcastManagerPath));
        File::put($broadcastManagerPath, $contents);

        $contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($pusherBroadcasterPath));
        File::put($pusherBroadcasterPath, $contents);
    }
}

然后将"php artisan fix:pusher"添加到composer.json文件:

"post-update-cmd": [
   "php artisan fix:pusher",
   "Illuminate\\Foundation\\ComposerScripts::postUpdate",
   "php artisan optimize"
]

答案 2 :(得分:1)

使用Pusher的第3版,我意识到Pusher \ Pusher的命名空间已经改变了。如果在设置了.env,BROADCAST_DRIVER = pusher时由作曲家配置,则显示该错误。检查日志,您可以找到问题所在的位置:

  

<强>&#39;供应商/ laravel /框架/ SRC /照亮/广播/ BroadcastManager.php&#34;

。如图所示,必须更改Pusher \ Pusher而不是Pusher的参考: enter image description here

然后找出函数 PusherBroadCaster 并更改Pusher \ Pusher的引用Pusher。

enter image description here

  

<强>供应商/ laravel /框架/ SRC /照亮/广播/广播/ PusherBroadcaster.php

答案 3 :(得分:-1)

只需转到vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php 并将“使用推送器”更改为“使用推送器/推送器”;