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:
(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"
]
回答3:
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
回答4:
Just go to vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php
and change "Use Pusher" to "Use Pusher/Pusher";