Class 'Pusher' not found

安稳与你 提交于 2019-12-04 19:56:11

问题


When I install Pusher package, I got an error "Class 'Pusher' not found".


回答1:


Claudio's diagnosis is correct, the namespace Pusher was added in version 3; but changing the Laravel files is not a recommended solution.

A better way is to create an alias in config/app.php. Under the 'aliases' key, add this to the array in the "Third Party Aliases" section:

'Pusher' => Pusher\Pusher::class,



回答2:


With the version 3 of Pusher I realized that there is changed the namespace for Pusher\Pusher. If configure by composer when set it out the .env, BROADCAST_DRIVER=pusher, it's showing that error. Checking out the log, you can find out where is the proble, located at this file:

'vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php"

. It's necessary change the references for Pusher\Pusher instead of Pusher like the image:

then find out the function PusherBroadCaster and change the reference Pusher for Pusher\Pusher.

vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php




回答3:


(OP posted the following answer in the question. The underlying issue is that version 3 of pusher-php-server introduces a namespace and so now requires use Pusher\Pusher.)

Create this command:

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);
    }
}

Then add "php artisan fix:pusher" to composer.json file:

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



回答4:


Just go to vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php and change "Use Pusher" to "Use Pusher/Pusher";



来源:https://stackoverflow.com/questions/45052853/class-pusher-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!