当我安装Pusher包时,我得到一个错误"Class 'Pusher‘not found“。
发布于 2017-07-30 05:27:04
Claudio的诊断是正确的,命名空间Pusher是在版本3中添加的;但是更改Laravel文件不是推荐的解决方案。
更好的方法是在config/app.php中创建别名。在“Aliases”键下,将以下内容添加到"Third Party Aliases“部分的数组中:
'Pusher' => Pusher\Pusher::class,发布于 2017-07-18 00:47:51
(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);
}
}然后在composer.json文件中添加"php artisan fix:pusher":
"post-update-cmd": [
"php artisan fix:pusher",
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]发布于 2017-07-26 19:37:07
在Pusher版本3中,我意识到Pusher\Pusher的名称空间发生了变化。如果在设置.env、BROADCAST_DRIVER=pusher时由composer进行配置,则会显示错误。查看日志,您可以找到问题所在,位于以下文件中:
'vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php"
。有必要更改Pusher\Pusher的引用,而不是像图像中那样的Pusher:

然后找到函数PusherBroadCaster并将引用Pusher更改为Pusher\Pusher。

vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php
https://stackoverflow.com/questions/45052853
复制相似问题